Hey, I put together a proper integration for Advanced Forum in my theme, and I think it should be simple enough to include this function in the module itself if you like. It could also be controlled by a setting (do you want it themed by advanced forum?) in configuration.

/**
 * Theme private messages as advanced forum posts.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("privatemsg-view" in this case.)
 */
function hook_preprocess_privatemsg_view(&$vars, $hook) {
  if (module_exists('advanced_forum')) {
    $vars['template_files'][] = 'adv-forum-post';

    $vars['top_post'] = FALSE;

    // Just use the date for the submitted on.
    $vars['submitted'] = format_date($vars['message']['timestamp']);

    // Assign the comment to the content variable for consistancy with nodes.
    $vars['content'] = $vars['message']['body'];

    // User information
    $vars['account'] = $vars['message']['author'];

    // Create the author pane
    $vars['author_pane'] = theme('author_pane', $vars['account'], advanced_forum_path_to_images(), 'privatemsg');

    // Create links
    $vars['links'] = $vars['message_actions'];

    // Title
    $vars['title'] = check_plain($vars['message']['subject']);

    // Load the signature.
    if (variable_get('user_signatures', 0) && $vars['account']->signature) {
      $vars['signature'] = check_markup($vars['account']->signature, $vars['account']->signature_format);
    }
  }
  return $vars;
}

It pretty much covers everything that Advanced Forum needs to theme it. As it is, it can be put into a theme, but I imagine it could be integrated directly into privatemsg instead. It only activates if module_exists('advanced_forum'); so it shouldn't add a dependency, just an option.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

meustrus’s picture

Status: Needs review » Active

OK, so it doesn't actually work. I though I saw results because I had copied the advf-forum-post.tpl.php file as privatemsg-view.tpl.php and some stuff that wasn't implemented before didn't work. I did catch an error in my code where it should say 'advf-forum-post.tpl.php' instead of 'adv-forum-post.tpl.php' but Drupal refuses to use the advf-forum-post template instead of the privatemsg-view template.

meustrus’s picture

Title: Advanced Forum Integration » Privatemsg Integration
Project: Privatemsg » Advanced Forum
Version: 6.x-1.2 » 6.x-1.1
Status: Active » Needs review

Moving to Advanced Forum, as it has become clear I've been coming at this from the wrong direction. I solved the problem by adding 'privatemsg_view' to $templates in advanced_forum_theme_registry_alter.

With that fix in place, and some additional improvements, here is the revised code:

/**
* Theme private messages as advanced forum posts.
*
* @param $vars
*   An array of variables to pass to the theme template.
* @param $hook
*   The name of the template being rendered ("privatemsg-view" in this case.)
*/
function advanced_forum_preprocess_privatemsg_view(&$vars, $hook) {
  if (module_exists('privatemsg')) {
    $vars['template_files'][] = 'adv-forum-post';

    // Not a node
    $vars['top_post'] = FALSE;

    // Just use the date for the submitted on.
    $vars['submitted'] = $vars['date'] = format_date($vars['message']['timestamp']);

    // Assign the comment to the content variable for consistancy with nodes.
    $vars['content'] = $vars['message_body'];

    // User information
    $vars['account'] = $vars['message']['author'];

    // Create the author pane
    $vars['author_pane'] = theme('author_pane', $vars['account'], advanced_forum_path_to_images(), 'privatemsg');

    // Create links
    $vars['links'] = $vars['message_actions'];

    // Title
    $vars['title'] = check_plain($vars['message']['subject']);

    // Load the signature.
    if (variable_get('user_signatures', 0) && $vars['account']->signature) {
      $vars['signature'] = check_markup($vars['account']->signature, $vars['account']->signature_format);
    }
  }
  return $vars;
}

All that remains from this is some theming considerations. The main problem is that privatemsg does not provide a plain array of message actions, so there is no easy way to change something for the $links in the post template. Specifically, they are class='message_actions' instead of class='links forum-links. There would either need to be a workaround in the theme (what I've done with my custom skin) or some way of changing the class of the <ul>.

Michelle’s picture

Version: 6.x-1.1 » 6.x-2.x-dev
Status: Needs review » Needs work

This is similar in idea to theming all comments even outside the forum so I can see a place for this. Will have to be in 2.x, though, so needs adapting as well as an option added to settings since not everyone will want this..

Thanks,

Michelle

meustrus’s picture

Working with the 2.x version. I see it's gotten a lot more complicated. So far I've added 'privatemsg_view', to the list in advanced_forum_theme_registry_alter, added this into 'includes/theme.inc':

/**
 * Preprocesses template variables for privatemsg.
 */
function advanced_forum_preprocess_privatemsg_view(&$variables) {
  if (TRUE) {
    include_once drupal_get_path('module', 'advanced_forum') . '/includes/advanced_forum_preprocess_privatemsg_view.inc';
    _advanced_forum_preprocess_privatemsg_view($variables);
  }
}

And created a new file, 'includes/advanced_forum_preprocess_privatemsg_view.inc':

// $Id$

/**
 * @file
 * Holds the contents of a preprocess function moved into its own file
 * to ease memory requirements and having too much code in one file.
 */

function _advanced_forum_preprocess_privatemsg_view(&$variables) {
  // Start a variable that will hold classes to attach to the containing div.
  $classes = array();
  
  // Add in our classes.
  $classes[] = 'forum-post clear-block';

  // Use our combined node/comment template file
  advanced_forum_add_template_suggestions('post', $variables['template_files']);

  // Not a node.
  $variables['top_post'] = FALSE;

  // Message body
  $variables['content'] = $variables['message_body'];

  // Use the message timestamp for date submitted
  $variables['submitted'] = $variables['date'] = format_date($variables['message']['timestamp']);

  // Use message actions for links
  $variables['links'] = $vars['message_actions'];

  /* User information / author pane */
  $variables['account'] = $variables['message']['author'];
  $variables['author_pane'] = theme('author_pane', $variables['account'], 'advanced_forum', variable_get('advanced_forum_user_picture_preset', ''));

  // Message subject
  $variables['title'] = check_plain($variables['message']['subject']);

  // Load Drupal's signature. signature_forum can't be supported since there is no $comment or $node object
  if (variable_get('user_signatures', 0) && !empty($vars['account']->signature)) {
    $vars['signature'] = check_markup($vars['account']->signature, $vars['account']->signature_format, FALSE);
  }

  // Fetch the current language
  global $language;
  $classes[] = $language->language;

  // Classes
  if (empty($variables['classes'])) {
    $variables['classes'] = implode(' ', $classes);
  }
  else {
    $variables['classes'] .= ' ' . implode(' ', $classes);  
  }
}

It mostly works. It doesn't pull any style CSS, though, and I don't know how to put in a setting to turn the preprocess on or off. I left an 'if (TRUE)' in place to gett the variable at a later time.

meustrus’s picture

Status: Needs work » Needs review

Could anybody take a look at this and help me do whatever else is necessary to get CSS in?

meustrus’s picture

Component: Code » Other module integration
FileSize
6.52 KB

Alright, I figured out the CSS issue, added a setting on the Advanced Forum configuration page, and put some considerable work into porting my changes to the dev-2.x version (it's quite different from alpha3! Maybe it's time for an alpha4?) There needs to be a small change in post.tpl.php in naked to allow for there to be no $node variable when checking if the post is published. While there, I noticed a bug and fixed it: the text is t("Unpublished Post") when it should be <?php t("Unpublished Post"); ?> (in other words, the t() is displayed as HTML instead of being processed as PHP).

Behold my patch of fancy fanciness! (I'm so proud of myself for figuring out how to make patches, or rather, for finding the manual page that describes how to do so)

Michelle’s picture

Thanks for doing this. I'm not ignoring you; just have been focused on getting the stuff finished up that I want to get into Alpha 4. I'll have a look at this soon as I can.

Michelle

meustrus’s picture

It should be noted that the integration works with privatemsg-6.x-2.x-dev. I remember changing some things when upgrading from privatemsg-6.x-1.3, but it could have been CSS for remaining parts of the page (participants, pager).

Also, there may be some theming considerations that I haven't touched on with the post links; since privatemsg does not provide an array of links, I had to use the existing HTML which has class='privatemsg-message-links' instead of class='links inline'.

There's also some additional CSS I used in my theme to...tame the participant list and pager:

.privatemsg-view-pager {
  float:right;
}
.privatemsg-message-participants {
  border:0 none;
  margin:0;
}
#privatemsg-new {
  clear: both;
  padding-top: .5em;
}

That I am sure only works for the dev version of privatemsg (the class names/ids are different).

meustrus’s picture

FileSize
6.49 KB

Also, there were some small errors in my previous patch related to getting class and ID for the post. I've attached a better patch.

Michsk’s picture

Great just what i need.

dreamdust’s picture

Patch works great!

Only problem I have noticed is it breaks the #new tag for new/unread private messages.

mcdruid’s picture

Status: Needs review » Needs work
FileSize
5.77 KB

meustrus, sorry it's taken us a long time to look at this.

Your patch in #9 no longer applies to 6.x-2.x-dev, so I've fixed that and attached the updated patch.

I've noticed at least one problem - the theming of PMs doesn't work well without author_pane, which may not be installed on some sites, as it's not a dependency of the 6.x-2.x branch. Without it the left hand side of the PM is an empty div. This should degrade better in the absence of author_pane.

On a more general note, I wonder if it would be a good idea to wrap the settings checkbox with a check for the presence of the privatemsg module, in order to reduce clutter when the settings's not relevant (you do explain that the setting won't do anything in the description).

I've tested your changes with privatemsg-6.x-1.5 (the current Recommended release) and 6.x-2.x-dev as at 2011-Jun-25. It seemed to work the same with both - I think it's important that the integration code works with the current recommended release, and not just the dev version (as suggested in your comment above, which was probably correct at the time).

If you - or anyone else who wants this functionality - are able to put a bit more work into this, I'll do my best to get it reviewed and committed.

Michelle’s picture

Is anyone still willing to work on this? Otherwise, let's bump it to D7.