]+href=")([^"]*)/emi', '"\\1"._send_qs("\2","'. $qs .'")', $body);
}
// call the delivery callback
$ret = (($count = call_user_func($deliver, $sender, $r, $values)) !== FALSE )
&& $ret;
// log the recipient if there are no nodes in the message
if (!count($values['nids'])) {
db_query("INSERT INTO {send_recipient}
( sid ,nid ,rid ,rtype ,mail, name, rcount )
VALUES ( %d ,%d ,%d ,'%s', '%s', '%s', %d )",
$values['sid'], 0, $rid, $rtype, $r_mail, $r_name, $count );
}
// log each node/user combination
foreach ($values['nids'] as $nid) {
db_query("INSERT INTO {send_recipient}
( sid ,nid ,rid ,rtype ,mail, name, rcount )
VALUES ( %d ,%d ,%d ,'%s', '%s', '%s', %d )",
$values['sid'], $nid, $rid, $rtype, $r_mail, $r_name, $count );
}
}
if ($ret) {
flood_register_event("send $module");
if ($values['sender_cc']) {
$self = $user->uid ? $user : $sender; //if it's a registered user, use their "real" address
mimemail($sender, $self, $subject, $values['body']);
drupal_set_message(t('A copy of this message has also been sent to %mail', array('%mail' => $values['sender_mail'])));
}
}
// get confirmation callback
if ($callback = module_invoke($module, 'send', 'confirm', $module)) {
$form_state['redirect'] = call_user_func($callback, $values);
}
$form_state['redirect'] = _send_confirm($values);
}
function _send_deliver($sender, $recipient, $values) {
if (mimemail($sender, $recipient, $values['subject'], $values['body'])) {
drupal_set_message(t('Message sent to %mail', array('%mail' => $recipient['mail'])));
}
// return the count of recipients
if (is_object($recipient) || isset($recipient['mail'])) return 1;
return count($recipient);
}
function _send_confirm($values) {
return 'node/'. $values['nids'][0];
}
/**
* build the body text
*/
function _send_body($message, $nids, $module, $mode) {
$modules = send_modules();
$body = '';
foreach ($nids as $nid) {
$node = node_load($nid);
switch ($mode) {
case 'title' :
$body .= $node->title .'
';
break;
case 'teaser' :
$text = node_view($node, TRUE, FALSE, FALSE);
$body .= _send_hook_modify($text, 'node', $module, $node->type, $node);
break;
case 'body' :
$text = node_view($node, FALSE, FALSE, FALSE);
$body .= _send_hook_modify($text, 'node', $module, $node->type, $node);
break;
}
}
// let modules prepend / append stuff to the body, or otherwise modify it
$body = _send_hook_modify($body, 'node', $module, $node->type, $node);
return $body;
}
// callback for querystring preg
function _send_qs($url, $qs) {
return $url . (strpos($url, '?') !== FALSE ? '&' : '?') . $qs;
}
function _send_hook_modify($text, $op, $module, $nodetype='', $node=NULL) {
$modules = send_modules();
foreach ($modules as $m => $name) {
$callback = module_invoke($m, 'send', $op, $nodetype, $node);
if ($callback && !is_null($altered = call_user_func($callback, $text))) {
$text = $altered;
}
}
return $text;
}
/**
* Set configuration variables for send
*/
function _send_value($name, $module='', $nodetype = '', $node = NULL, $value = NULL) {
$nid = is_object($node) ? $node->nid : 0;
$pernode = variable_get("{$module}_{$nodetype}_pernode", 0);
// set a new value
if (!is_null($value)) {
if ($nid && !$pernode) {
return; // trying to set a per-node value but can't
}
db_query("DELETE FROM {send_setting}
WHERE name='%s' AND module='%s' AND nodetype='%s' AND nid=%d"
, $name, $module, $nodetype, $nid);
/* We override in this order: module, nodetype, node
don't set this value if it's the same as the one above it in the stack
*/
if ($nid) {
// this node has the same value as its nodetype
if ($value == _send_value($name, $module, $nodetype)) return;
}
elseif ($nodetype) {
// this nodetype has the same value as its module
if ($value == _send_value($name, $module)) return;
// for future consistency, delete children that would inherit this value
db_query("DELETE FROM {send_setting}
WHERE name='%s' AND module='%s' AND nodetype='%s' AND value='%s'"
, $name, $module, $nodetype, $value);
}
elseif ($module) {
// this module has the same value as the default
if ($value == _send_value($name)) return;
// for future consistency, delete children that would inherit this value
db_query("DELETE FROM {send_setting}
WHERE name='%s' AND module='%s' AND value='%s'"
, $name, $module, $value);
}
// save the value
db_query("INSERT INTO {send_setting} ( name, module, nodetype, nid, value )
VALUES ('%s', '%s', '%s', %d, '%s')", $name, $module, $nodetype, $nid, $value);
return;
}
// try getting value from variables to save resources
if (!$pernode && $val = variable_get("{$module}_{$nodetype}_{$name}", FALSE)) {
return $val;
}
// get value from database
if ($val = db_result(db_query("SELECT value FROM {send_setting}
WHERE name='%s' AND
nid IN (0, %d) AND nodetype IN ('', '%s') AND module IN ('', '%s')
ORDER BY (nid = 0), (nodetype = ''), (module = '')
LIMIT 1", $name, $nid, $nodetype, $module))) {
return $val;
}
// return module's default value
if ($val = module_invoke($module, 'send', $name, $module, $nodetype, $node)) {
return $val;
}
// return send's default value
if ($val = module_invoke('send', 'send', $name, $module, $nodetype, $node)) {
return $val;
}
return;
}
function theme_send_form(&$form) {
$from = drupal_render($form['from']);
$to = drupal_render($form['to']);
$buttons = drupal_render($form['buttons']);
$subject = drupal_render($form['subject']);
$message = drupal_render($form['message']);
$template= check_markup(drupal_render($form['template']), $form['template']['template_format']['#value']);
$body = drupal_render($form['body']);
$extra = drupal_render($form);
$replace = array('%message', '%body');
$values = array($message, $body);
$content = str_replace($replace, $values, $template);
$headers = theme('table', array(t('From'), t('To')), array(array('data' => array($from, $to), 'valign' => 'top')), array('width' => '100%'));
return $headers .'
'. $extra . $buttons .'
'. $subject .'
'. $content;
}
function theme_send_template() {
$template = "%message\n%body\n";
return $template;
}
function theme_send_body($values) {
$template = check_markup($values['template'], $values['template_format']);
$message = '';
if ($values['message']) {
$message = ''. check_markup($values['message']) .'
';
}
$body = $values['node_body'];
$replace = array('%message', '%body');
$values = array($message, $body);
return str_replace($replace, $values, $template);
}