[support] Help: Privatemsg Module

Antoine Spadoni antoine.spadoni at gmail.com
Fri Aug 10 12:20:42 UTC 2007


Hi,

I am looking to do a slight modification in my Drupal installation within
the *Private*msg module.

Below my nodes, I added a contact author link and now I want to display the
Title of the node within the Subject Field of the message.

So first, I added the nid of the node in the URL of the message in order to
be able to retrieve the title of the node:
/**
 * Implementation of hook_link().
 */
function privatemsg_link($type, $node = NULL, $teaser = FALSE) {
  global $user;
  static $access = array();
  $links = array();
  $nid = $node->nid;
  $uid = $node->uid;
  if ($type == 'comment' && $node->nid) {
    $node = node_load($node->nid);
  }
  if (user_access('access private messages') && in_array($teaser ? 'teaser'
: $type, variable_get('privatemsg_link_'. $node->type, array())) && $uid !=
$user->uid && $user->privatemsg_allow) {
    if (!isset($access[$uid])) {
      $author = user_load(array('uid' => $uid));
      $access[$uid] = user_access('access private messages', $author) &&
$author->uid && $author->privatemsg_allow;
    }
    if ($access[$uid]) {
      $links['privatemsg_write_to_author'] = array(
        'title' => t('Write to seller'),
        'href' => 'privatemsg/new/'.$uid.'/'. $nid,
      );
    }
  }
  return $links;
}

But now I am unable to manage to modify properly this function and display
the Title of the node within the Subject Field of the message:
/**
 * Provides a form to write a private message.
 */
function privatemsg_new_form() {
  global $user;
  $message = 0;

  $op = arg(1);
  if ($op == 'reply') {
    $message = arg(2);
  }
  else if (($uid = arg(2)) && ($msg->recipient = db_result(db_query('SELECT
name FROM {users} WHERE uid = %d', $uid)))) {
    $message = $msg;
  }

  if ($message && !is_object($message)) {
    // This is a reply to another message
    $message = db_fetch_object(db_query('SELECT thread, subject, message,
u.name AS recipient FROM {privatemsg} p INNER JOIN {users} u ON u.uid =
p.author WHERE id = %d AND recipient = %d', $message, $user->uid));

    if (!stristr($message->subject, t('Re:'))) {
      $message->subject = t('Re:') .' '. $message->subject;
    }

    // quoting; [quote] if default input format uses bbcode or quote, else >
quoting
    foreach
(filter_list_format(filter_resolve_format(FILTER_FORMAT_DEFAULT)) as
$filter) {
      if ($filter->module == 'bbcode' || $filter->module == 'quote') {
        $bbcode = TRUE;
        break;
      }
    }
    if (isset($bbcode)) {
      $message->message = "\n\n[quote=". $message->recipient .']'.
$message->message .'[/quote]';
    }
    else {
      $message->message = "\n\n\n". str_replace("\n", "\n> ", "\n".
$message->message);
    }
  }

  if (isset($_SESSION['recipients'])) {
    $recipient = implode(', ', $_SESSION['recipients']);
    unset($_SESSION['recipients']);
  }


  $form = array('preview' => array());

  $form['thread'] = array('#type' => 'value', '#value' =>
isset($message->thread) ? $message->thread : 0);
  $form['header']['#theme'] = 'privatemsg_new_msg_header';
  $form['header']['recipient'] = array(
    '#type' => 'hidden',
    '#title' => t('Purchase'),
    '#description' => t('Separate multiple names with commas.'),
    '#default_value' => isset($recipient) ? $recipient :
$message->recipient,
    '#autocomplete_path' => 'privatemsg/autocomplete',
    '#size' => 50,
    '#maxlength' => 1000,
  );

  $form['header']['subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#default_value' => $message->subject,
    '#size' => 50,
    '#maxlength' => 64,
  );

  $form['privatemsgbody'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#default_value' => $message->message,
    '#cols' => 80,
    '#rows' => 6,
  );
  $form[] = filter_form($message->format);
  $form[] = array(
    '#type' => 'submit',
    '#value' => t('Preview')
  );
  $form[] = array(
    '#type' => 'submit',
    '#value' => t('Send private message')
  );
  $form['#after_build'] = array('_privatemsg_new_preview');

  drupal_add_js(drupal_get_path('module', 'privatemsg') .'/privatemsg.js');

  return $form;
}

Any help to get this modification done would be greatly appreciated!

Thanks,

Antoine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20070810/6cdcd933/attachment.htm 


More information about the support mailing list