Index: pm_workflow_ng/pm_workflow_ng.info =================================================================== RCS file: pm_workflow_ng/pm_workflow_ng.info diff -N pm_workflow_ng/pm_workflow_ng.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pm_workflow_ng/pm_workflow_ng.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +; $Id$ +name = Private message workflow-ng +description = implements workflow-ng functionality +dependencies = token workflow_ng privatemsg +package = Mail Index: pm_workflow_ng/README.txt =================================================================== RCS file: pm_workflow_ng/README.txt diff -N pm_workflow_ng/README.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pm_workflow_ng/README.txt 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ +******************************************************************** + D R U P A L M O D U L E +******************************************************************** +Name: pm_workflow_ng +Author: Dominik Kiss nodestroy at drupal.org +Drupal Version: 5 +******************************************************************** +DESCRIPTION: + +This module extends privatemsg module with workflow-ng functionality. + +It implements hook_privatemsg() and calls workflow-ng events on +the various privatemsg actions (listed below). + +- prune (Message is permanently removed) +- delete (Message is marked as deleted) +- view (Message is about to be displayed for viewing) +- sent (Message was sent) + +There is also a workflow-ng action provided, that means you can send +a privatemsg via workflow-ng (e.g: at buddylist2 userA requests to +add userB to his buddylist. after this, a workflow-ng event is +thrown, and a privatemsg will be sent to userB). + +Default Configuration: +Send a eMail and log to watchdog, when a privatemsg is sent. + +NOTE: With the action "Send a private message" the action "Load user +by name" is very usefull, so you can configure a specific user +(e.g: admin) as sender. + +******************************************************************** +INSTALLATION: + +1. Download the module from drupal.org and place it into your drupal + directory (/sites/all/modules) + +2. Enable the module at: + administer -> site building -> modules + + Index: pm_workflow_ng/pm_workflow_ng_token.inc =================================================================== RCS file: pm_workflow_ng/pm_workflow_ng_token.inc diff -N pm_workflow_ng/pm_workflow_ng_token.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pm_workflow_ng/pm_workflow_ng_token.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,42 @@ +message); + $tokens['subject'] = check_plain($object->subject); + $tokens['timestamp'] = check_plain($object->timestamp); + $tokens['id'] = check_plain($object->id); + $tokens['format'] = check_plain($object->format); + $tokens['newmsg'] = check_plain($object->newmsg); + $tokens['folder'] = check_plain($object->folder); + + return $tokens; + } +} + +/** + * Implementation of hook_token_list() + */ +function pm_workflow_ng_token_list($type = 'all') { + if ($type == 'message' || $type == 'all') { + $tokens['message']['message'] = t("Message which is send by userA to userB."); + $tokens['message']['subject'] = t("Subject of message."); + $tokens['message']['timestamp'] = t("Timestamp when message was sent."); + $tokens['message']['id'] = t("A unique ID of the message."); + $tokens['message']['format'] = t("Format of the message."); + $tokens['message']['newmsg'] = t("Is the message unopened?"); + $tokens['message']['folder'] = t("The folder which contains the message."); + return $tokens; + } +} Index: pm_workflow_ng/pm_workflow_ng_action.inc =================================================================== RCS file: pm_workflow_ng/pm_workflow_ng_action.inc diff -N pm_workflow_ng/pm_workflow_ng_action.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pm_workflow_ng/pm_workflow_ng_action.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,82 @@ + array( + '#label' => t('Send a private message'), + '#arguments' => array( + 'user_rep' => array('#entity' => 'user', '#label' => t('Recipient')), + 'user_sen' => array('#entity' => 'user', '#label' => t('Sender')), + ), + '#module' => t('Privatemsg'), + ), + ); +} + +/** + * Sends the Privatemsg + * + * @param $user_rep + * Recipient of the Message + * @param $user_sen + * Sender of the Message + * @param $settings + * Associative Array with 'subject' and 'message' as keys + */ +function pm_workflow_ng_action_send_privatemsg($user_rep, $user_sen, $settings) { + // send pm + _privatemsg_send($user_sen, $user_rep, $settings['subject'], $settings['message'], FILTER_FORMAT_DEFAULT); +} + +/** + * Provide Workflow-ng configuration form + */ +function pm_workflow_ng_action_send_privatemsg_form($settings = array(), $argument_info) { + $form = array(); + + $form['subject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#size' => '40', + '#default_value' => $settings['subject'], + '#description' => t('Subject of privatemsg.'), + ); + + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Message'), + '#default_value' => $settings['message'], + '#description' => t('The private message that should be send.'), + ); + + workflow_ng_token_replacement_help($form, $argument_info); + + $form['error'] = array( + '#type' => 'checkbox', + '#title' => t('Display as error message'), + '#default_value' => $settings['error'], + ); + + return $form; +} + +/** + * returns the needed settings + */ +function pm_workflow_ng_action_send_privatemsg_submit($form_id, $form_values) { + $settings = workflow_ng_token_get_settings(array('subject', 'message'), $form_values); + return $settings + array('error' => $form_values['error']); +} + + Index: pm_workflow_ng/pm_workflow_ng.module =================================================================== RCS file: pm_workflow_ng/pm_workflow_ng.module diff -N pm_workflow_ng/pm_workflow_ng.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pm_workflow_ng/pm_workflow_ng.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,168 @@ + array( + '#label' => t('Message is permanently removed'), + '#module' => t('Privatemsg'), + '#arguments' => workflow_ng_events_hook_privatemsg_arguments('prune message'), + ), + 'privatemsg_delete' => array( + '#label' => t('Message is marked as deleted'), + '#module' => t('Privatemsg'), + '#arguments' => workflow_ng_events_hook_privatemsg_arguments('delete message'), + ), + 'privatemsg_view' => array( + '#label' => t('Message is about to be displayed for viewing'), + '#module' => t('Privatemsg'), + '#arguments' => workflow_ng_events_hook_privatemsg_arguments('viewed message'), + ), + 'privatemsg_sent' => array( + '#label' => t('Message was sent'), + '#module' => t('Privatemsg'), + '#arguments' => workflow_ng_events_hook_privatemsg_arguments('sent message'), + ), + ); +} + +/** + * arguments function + */ +function workflow_ng_events_hook_privatemsg_arguments($message_label) { + return array( + 'message' => array('#entity' => 'message', '#label' => t('Message')), + 'userA' => array('#entity' => 'user', '#label' => t('UserA, sender of message'), '#handler' => 'workflow_ng_events_argument_privatemsg_sender'), + 'userB' => array('#entity' => 'user', '#label' => t('UserB, recipient of message'), '#handler' => 'workflow_ng_events_argument_privatemsg_recipient'), + ) + workflow_ng_events_global_user_argument(); +} + +/** + * handler to get sender + */ +function workflow_ng_events_argument_privatemsg_sender($message) { + $userA = user_load(array('uid' => $message->uid)); + return $userA; +} + +/** + * handler to get recipient + */ +function workflow_ng_events_argument_privatemsg_recipient($message) { + $userB = user_load(array('uid' => $message->recipient)); + return $userB; +} + +/** + * Implementation of hook_privatemsg() + */ +function pm_workflow_ng_privatemsg($message, $op) { + if (in_array($op, array('prune', 'delete', 'view', 'sent'))) { + workflow_ng_invoke_event('privatemsg_'.$op, $message); + } +} + +/** + * Implementation of hook_configuration() + */ +function pm_workflow_ng_configuration() { + $configurations = array ( + 'user_gets_pm_send_mail' => + array ( + '#altered' => false, + '#id' => 1, + '#module' => 'workflow-ng', + '#event' => 'privatemsg_sent', + '#label' => '[MAIL] UserB gets privatemsg from UserA', + '#type' => 'configuration', + '#active' => 1, + 1 => + array ( + '#id' => 2, + '#name' => 'workflow_ng_action_watchdog', + '#type' => 'action', + '#settings' => + array ( + 'severity' => '0', + 'type' => 'workflow-ng', + 'message' => '[userB:user] ([userB:uid]) got a privatemsg from [userA:user] ([userA:uid])', + 'message_args' => + array ( + 0 => 'userA', + 1 => 'userB', + ), + 'link' => '', + 'link_args' => + array ( + ), + ), + '#label' => 'Log to watchdog', + ), + 0 => + array ( + '#id' => 3, + '#type' => 'action', + '#label' => 'Send a mail to a user', + '#name' => 'workflow_ng_action_mail_to_user', + '#settings' => + array ( + 'from' => '[userA:site-mail]', + 'from_args' => + array ( + 0 => 'userA', + ), + 'subject' => '[userA:site-name]: new message from [userA:user]', + 'subject_args' => + array ( + 0 => 'userA', + ), + 'message' => 'Hi [userB:user], + +you got a new private message from [userA:user]. + +************************** +subject: [message:subject] +message: +[message:message] +************************** + +your +[userA:site-name] team', + 'message_args' => + array ( + 0 => 'userA', + 1 => 'userB', + 2 => 'message', + ), + ), + '#argument map' => + array ( + 'userB' => 'user', + ), + ), + '#name' => 'user_gets_pm_send_mail', + ), +); + + return $configurations; +} + + +