I was making some changes to Author Pane on Coulee Region Online and realized the integration in Privatemsg is really out of date. Here's an updated version:

// $Id$

/**
 * @file
 *   Provides a preprocess function to integrate Privatemsg with Author Pane.
 */

/**
 * Implements hook_preprocess_author_pane().
 */
function privatemsg_preprocess_author_pane(&$variables) {
  // Check if this preprocess needs to be run given who's calling it.
  if (!author_pane_run_preprocess('privatemsg', $variables['caller'])) {
    return;
  }

  global $user;
  $account = $variables['account'];
  $account_id = $account->uid;
  $account_name = $account->name;
  
  if ($account_id != $user->uid) {
    $url = privatemsg_get_link($account);
    if (!empty($url)) {
      $variables['privatemsg'] = l(t('Send PM') . '<span></span>', $url, array('attributes' => array('class' => 'author-privatemsg-icon', 'title' => t('Send @name a private message', array('@name' => $account_name))), 'html' => TRUE));
    }
  }
}

/**
 * Implementation of hook_author_pane_allow_preprocess_disable().
 */
function privatemsg_author_pane_allow_preprocess_disable() {
  return array('privatemsg' => 'Privatemsg');
}

Thanks,

Michelle

Comments

berdir’s picture

Status: Active » Fixed

Thank you, commited to 7.x-1.x-dev and 6.x-2.x-dev. I replaced "Send PM" with "Send private message" since we don't use PM anywhere else.

michelle’s picture

That's fine. I just used "PM" because it's shorter and the words need to fit in cramped spaces but people can always use the t() to change it if they need to.

Thanks for the quick response!

Michelle

michelle’s picture

Status: Fixed » Active

I just realized I'm still using 1.x. This hasn't even been tested against 2.x so I don't know if there's any API changes that might affect it. Could you commit against 1.x, please? I realize that's the stable branch but this is a self contained file that only runs in conjunction with Author Pane so I don't see how it could affect the stability of 1.x.

Thanks!

Michelle

berdir’s picture

Version: » 6.x-1.x-dev

Sure, commited. I wasn't sure if you've chosen the 2.x branch for a reason but forgot to ask.

berdir’s picture

Status: Active » Fixed
michelle’s picture

No reason, just a goof up. I've got so many modules installed I forget which ones I'm using the cutting edge on. LOL! Not this time. Still on 1.x for now. If you have a moment, could you double check that $url = privatemsg_get_link($account); is still valid in 2.x? If not, it will need to be changed in the 2.x version. Everything else should be the same provided whatever you change it to still provides the URL.

I'll test against 2.x at some point but a quick check may save people troubles if the API changed. :)

Thanks,

Michelle

berdir’s picture

privatemsg_get_link() has not changed, so that should be fine.

fugazi’s picture

Hello,
to update 6x-2.x-dev 11.07.2010 I have the error message.
Fatal error: Call to undefined function author_pane_run_preprocess() in sites/all/modules/privatemsg/privatemsg.author-pane.inc on line 14

Thank you very much

michelle’s picture

Status: Fixed » Active

Shoot, my bad on that. I've had my head in AP 2.x so long I forgot there's still people using 1.x.

This should work but I don't have time to test it right now:

  if (function_exists('author_pane_run_preprocess') && !author_pane_run_preprocess('privatemsg', $variables['caller'])) {
    return;
  }

Also, Berdir, if you have a moment could you look at #850474: private message integration doesn't work with the last update ? If the API hasn't changed, I'm not sure what could be causing the problem that user is having.

Sorry for making a mess of this. The code I gave you is working fine on my site so I thought it was safe and I just completely spaced on AP 1.x users. :(

Michelle

junro’s picture

Subscribe to follow the evolution of the integration :)

berdir’s picture

Status: Active » Fixed

Commited to 6.x-1.x and 6.x-2.x. I assume you will only port 2.x to Drupal 7 :)

fugazi’s picture

#9 oh it's wonderful it's all back, thank you ..

michelle’s picture

Correct, only AP 2.x will be ported. In fact, AP 1.x is going to be deprecated as soon as I make the change to AF 1.x to work with AP 2.x. But I can't leave it broken for people using the dev of privatemsg in the mean time so thanks for making the change. :)

Michelle

fugazi’s picture

#9 Unfortunately, the link to the icon is no longer given. What I could do Author Pane 6.x-1.1. Thanks

michelle’s picture

I apologize because I appear to have made a complete mess of this. :( I'm so focused on getting 2.0 out that 1.x completely fell off my radar.

For 1.x users, I suggest replacing the contents of the file with this:

http://drupalcode.org/viewvc/drupal/contributions/modules/privatemsg/pri...

I will work tonight to come up with a solution that works for both branches and test it against both before asking for anything else to be committed.

Michelle

fugazi’s picture

Hi,
Thanks for any tip, it works again. I know how much work goes into such modules. And it is normal that there mistakes. Happen I hope you understood my bad English. I would like in the highest form
thank you for such great modules. Thank you

michelle’s picture

Status: Fixed » Needs review

Ok, this is tested against 2.x. I have not tested it against 1.x, yet, because I don't have a site set up running it. If someone using 1.x could test it, that would help out. Otherwise I'll get a 1.x site set up as soon as I can.

// $Id$

/**
* @file
*   Provides a preprocess function to integrate Privatemsg with Author Pane.
*/

/**
* Implements hook_preprocess_author_pane().
*/
function privatemsg_preprocess_author_pane(&$variables) {
  global $user;
  $account = $variables['account'];
  $account_id = $account->uid;
  $account_name = $account->name;
  
  if (function_exists('author_pane_api') && author_pane_api() == "2") {
    // Author Pane 2.x
    
    // Check if this preprocess needs to be run given who's calling it.
    if (!author_pane_run_preprocess('privatemsg', $variables['caller'])) {
      return;
    }

    if ($account_id != $user->uid) {
      $url = privatemsg_get_link($account);
      if (!empty($url)) {
        $variables['privatemsg'] = l(t('Send PM') . '<span></span>', $url, array('attributes' => array('class' => 'author-privatemsg-icon', 'title' => t('Send @name a private message', array('@name' => $account_name))), 'html' => TRUE));
        
        // Early versions of the template used this variable so fill it for
        // backwards compatability.
        $variables['privatemsg_link'] = $variables['privatemsg'];
      }
    }
  }
  else {
    // Author Pane 1.x
    
    $image_path = $variables['image_path'];
    
    // Send private message
    if ($url = privatemsg_get_link($account)) {
      $img = theme('image', "$image_path/private-message.png", t('Send private message'), t('Send private message'), NULL, TRUE);
      $variables['privatemsg'] = l($img, $url, array('absolute' => TRUE, 'html' => TRUE));
      $variables['privatemsg_link'] = l(t('Send PM') . '<span></span>', $url, array('attributes' => array('class' => 'author-privatemsg-icon'), 'html' => TRUE));
    }
  }
}

/**
* Implementation of hook_author_pane_allow_preprocess_disable().
*/
function privatemsg_author_pane_allow_preprocess_disable() {
  return array('privatemsg' => 'Privatemsg');
}
fugazi’s picture

Hi, I have tested it and so far everything seeming to work very well. thanks for the quick change.

jcmarco’s picture

Confirmed, #17 works with author pane 2.x

michelle’s picture

@Berdir: Ok, it's been tested by other people in both 1.x and 2.x but I've only tested in 2.x. Since I don't currently have a 1.x site set up, it may be a few days or more before I can get to it. I'll let it be your call if you want to commit it based on the other reviews or wait until I can get to it. Again, sorry for making such a mess of this. :(

Michelle

fugazi’s picture

Confirmed, #17 works with author pane 1.x

michelle’s picture

Status: Needs review » Reviewed & tested by the community

I've tested it with AP 1.x as well, now, too. Should be good to go. :)

Michelle

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, commited to 6.x-1.x and 6.x-2.x

michelle’s picture

Thanks!

Michelle

Status: Fixed » Closed (fixed)

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