uid; } /** * Display a list of threads. * * @param $fragments * Query fragments * @param $account * User object */ function hook_privatemsg_sql_list_alter(&$fragment, $account) { } /** * Display a list of sent messages. * * @param $fragments * Query fragments * @param $account * User object */ function hook_privatemsg_sql_list_sent_alter(&$fragment, $account) { } /** * Load a single message. * * @param $fragments * Query fragments * @param $pmid * message id, pm.mid * @param $account * User object */ function hook_privatemsg_sql_load_alter(&$fragment, $pmid, $account) { } /** * Load all message id's of a thread. * * @param $fragments * Query fragments * @param $thread_id * Thread id, pmi.thread_id is the same as the mid of the first * message of that thread * @param $account * User object */ function hook_privatemsg_sql_messages_alter(&$fragment, $thread_id, $account) { } /** * Load the participants of a thread. * * @param $fragments * Query fragments * @param $thread_id * Thread id, pmi.thread_id is the same as the mid of the first * message of that thread */ function hook_privatemsg_sql_participants_alter(&$fragment, $thread_id) { } /** * Loads all unread messages of a user (only the count query is used). * * @param $fragments * Query fragments * @param $account * User object */ function hook_privatemsg_sql_unread_count_alter(&$fragment, $account) { } /** * @} */ /** * @defgroup api API functions * * There are two different functions to send messages. * Either by starting a @link privatemsg_new_thread new thread @endlink * or @link privatemsg_reply reply @endlink to an existing thread. * * There is also a function which returns a link to the privatemsg new message * form with the recipient pre-filled if the user is allowed to. * privatemsg_get_link(). */ /** * @defgroup message_hooks Message hooks * All message-level hooks look like hook_privatemsg_message_op, * where op is one of the following: * - @link hook_privatemsg_message_load load @endlink: Called when a full * message is loaded similiar to nodeapi_load, new values can be returned and * will be added to $message, parameter: $message * - @link hook_privatemsg_message_validate validate @endlink: Validation, * before the message is sent/saved. Return validation errors as array, * parameter: $message, $form = FALSE * - @link hook_privatemsg_message_presave_alter presave_alter @endlink: Last * changes to $message before the message is saved, parameter: $message * - @link hook_privatemsg_message_insert insert @endlink: message has been * saved, $message has been updated with the mid and thread_id, * parameter: $message * - @link hook_privatemsg_message_delete delete @endlink: the message is * going to be deleted, parameter: $message * - @link hook_privatemsg_message_view_alter view_alter @endlink: the message * is going to be displayed, parameter: $vars * * In hooks with _alter suffix, $message is by reference. * * $message is an array, with all the relevant information about the message. * The information in there can be changed/extended by modules, but looks * typically like this: * @code * array ( * 'mid' => 3517, // message id, identifies a message * 'author' => 27, // author id * 'subject' => 'raclebugav', // Message subject * 'body' => 'bla bla', // Body of the message * 'timestamp' => 351287003, // unix timestamp, creation time * 'is_new' => 0, // If the message has been read by the user * 'thread_id' => 3341, // thread id, this is actually the mid from the first * message of the thread * ) * @endcode */ /** * @addtogroup message_hooks * @{ */ /** * Is called after the message has been loaded. * * Return data will be merged with the $message array. * * @param $message * Message array */ function hook_privatemsg_message_load($message) { return array('my_key' => 'my_value'); } /** * Is called when a message is deleted. * * Note: The message is actually only marked as deleted and only for the current * user. * @todo There is no "undelete" hook * * @param $message * Message array */ function hook_privatemsg_message_delete($message) { } /** * Is called when a message is flushed. * * The message will be deleted from the database, remove any related data here. * * @param $message * Message array */ function hook_privatemsg_message_flush($message) { } /** * Validate a message before it is sent/saved in the database. * * Validation errors can be returned, either as a string or as array when there * are multiple errors. If the $form flag is set, errors should be reported * with form_set_error instead. * * @todo adapt api return value changes * * @param $message * Message array */ function hook_privatemsg_message_validate($message, $form = FALSE) { global $_privatemsg_invalid_recipients; $_privatemsg_invalid_recipients = array(); $errors = array(); foreach ($message['recipients'] as $recipient) { if ($recipient->name == 'blocked user') { $_privatemsg_invalid_recipients[] = $recipient->uid; $errors[] = t("Message can't be sent to @name because he has been blocked"); } } } /** * Change the message before it is stored. * * Alter the message, for example remove recipients that have been detected as * invalid or forbidden in the validate hook. * * @param $message * Message array */ function hook_privatemsg_message_presave_alter(&$message) { // delete recipients which have been marked as invalid global $_privatemsg_invalid_recipients; foreach ($_privatemsg_invalid_recipients as $invalid) { unset($message['recipients'][$invalid]); } } /** * Act on the $vars before a message is displayed. * * This is called in the preprocess hook of the privatemsg-view template. * The $message data is aviable in $vars['message']. * * @param $var * Template variables */ function hook_privatemsg_message_view_alter(&$var) { // add a link to each message $vars['message_links'][] = array('title' => t('My link'), 'href' => '/path/to/my/action/'. $vars['message']['mid']); } /** * This hook is executed after the message has been saved. * * $message is updated with mid and thread id. Use this hook to store data, * that needs to point to the saved message for example attachments. * * @param $message * Message array */ function hook_privatemsg_message_insert($message) { _mymodule_save_data($message['mid']); } /** * @} */ /** * @defgroup generic_hooks Generic Hooks * @{ * * Some generic hooks that can't be categorized. */ /** * Check if $author can send $recipient a message. * * Return a message if it is not alled, nothing if it is. This hook is executed * for each recipient. * * @param $author * Author of the message to be sent * @param $recipient * Recipient of the message */ function hook_privatemsg_block_message($author, $recipient) { } /** * Add content to the view thread page. * * Each element in content contains a 'value' and a '#weight' key, the weight * is used set the order of the different parts. * * @param $content * Content array * @param $message_count * Amount of messages */ function hook_privatemsg_view_messages($content, $message_count) { } /** * List of possible templates. */ function hook_privatemsg_view_template() { } /** * Expose operations/actions which can be executed on threads. * * Return an array of operations to privatemsg, the key of each operation is the * operation key or name. * * @see _privatemsg_action_form() * @see privatemsg_list_submit() */ function hook_privatemsg_thread_operations() { return array( 'operation key' => array( 'label' => 'Label of the operation. Only use this if the operation should be displayed automatically in the action form', 'callback' => 'privatemsg_thread_change_status', // Function callback that will be executed. 'callback arguments' => array('status' => PRIVATEMSG_READ), // Additional arguments to above function 'undo callback' => 'privatemsg_thread_change_status', // Provide a function which can "undo" the operation. Optional. 'undo callback arguments' => array('status' => PRIVATEMSG_UNREAD), // Additional arguments to above function. ), ); } /** * @} */