| 1 |
<?php |
<?php |
| 2 |
// $Id: notify.module,v 2.67.2.2 2007/07/15 03:13:08 augustin Exp $ |
// $Id: notify.module,v 2.73 2009/01/14 01:10:53 matt2000 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 12 |
$output .= t('<p>You can</p><ul><li>set up your site to run tasks automatically at required intervals. For more information, see <a href="@admin-help-system">cron</a>.</li><li>administer notify <a href="@admin-settings-notify">administer >> settings >> notify</a>.</li></ul>', array('@admin-help-system' => url('admin/help/system'), '@admin-settings-notify' => url('admin/settings/notify'))); |
$output .= t('<p>You can</p><ul><li>set up your site to run tasks automatically at required intervals. For more information, see <a href="@admin-help-system">cron</a>.</li><li>administer notify <a href="@admin-settings-notify">administer >> settings >> notify</a>.</li></ul>', array('@admin-help-system' => url('admin/help/system'), '@admin-settings-notify' => url('admin/settings/notify'))); |
| 13 |
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@notify">Notify page</a>.', array('@notify' => 'http://www.drupal.org/handbook/modules/notify/')) .'</p>'; |
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@notify">Notify page</a>.', array('@notify' => 'http://www.drupal.org/handbook/modules/notify/')) .'</p>'; |
| 14 |
return $output; |
return $output; |
|
case 'admin/settings/notify': |
|
|
$output .= '<fieldset><legend>'. t('Warning!') .'</legend><p>'. t('Nodes or comments which include <strong>PHP code</strong> might in some circumstances <strong>break your web site</strong>. They might cause <em>notify</em> to run in a loop or completely malfunction. This is not a bug: if you are adding some PHP code into your content, <em>you are supposed to know what you are doing</em>. See the <a href="@notify">handbook page for notify.module</a>.', array('@notify' => 'http://www.drupal.org/handbook/modules/notify/')) .'</p></fieldset>'; |
|
|
return $output; |
|
| 15 |
} |
} |
| 16 |
} |
} |
| 17 |
|
|
| 33 |
604800 => format_interval(604800), |
604800 => format_interval(604800), |
| 34 |
1209600 => format_interval(1209600), |
1209600 => format_interval(1209600), |
| 35 |
2419200 => format_interval(2419200), |
2419200 => format_interval(2419200), |
| 36 |
1000000000 => t('Never'), |
-1 => t('Never'), |
| 37 |
); |
); |
| 38 |
|
|
| 39 |
$form = array(); |
$form = array(); |
| 46 |
'#description' => t('How often should new content notifications be sent? Requires cron to be running.'), |
'#description' => t('How often should new content notifications be sent? Requires cron to be running.'), |
| 47 |
); |
); |
| 48 |
|
|
| 49 |
|
$form['notify_send_hour'] = array( |
| 50 |
|
'#type' => 'select', |
| 51 |
|
'#title' => t('Send notifications during this hour'), |
| 52 |
|
'#default_value' => variable_get('notify_send_hour', date('G', variable_get('notify_send_last', 0))), |
| 53 |
|
'#options' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23), |
| 54 |
|
'#description' => t('Hour of the day to send noticiations, on 24 hour clock.'), |
| 55 |
|
); |
| 56 |
|
|
| 57 |
$form['notify_attempts'] = array( |
$form['notify_attempts'] = array( |
| 58 |
'#type' => 'select', |
'#type' => 'select', |
| 59 |
'#title' => t('Number of failed sends after which notifications are disabled'), |
'#title' => t('Number of failed sends after which notifications are disabled'), |
| 68 |
* Implementation of hook_cron(). |
* Implementation of hook_cron(). |
| 69 |
*/ |
*/ |
| 70 |
function notify_cron() { |
function notify_cron() { |
| 71 |
if (time() - variable_get('notify_send_last', 0) > variable_get('notify_send', 86400)) { |
$send_last = variable_get('notify_send_last', 0); |
| 72 |
|
$send_interval = variable_get('notify_send', 86400); |
| 73 |
|
$send_hour = variable_get('notify_send_hour', date('G', variable_get('notify_send_last', 0))); |
| 74 |
|
if ( (time() - $send_last > $send_interval) |
| 75 |
|
&& (date('G', time()) > $send_hour) |
| 76 |
|
&& ($send_interval != -1) //special case of settings to send 'never' |
| 77 |
|
) { |
| 78 |
_notify_send(); |
_notify_send(); |
| 79 |
variable_set('notify_send_last', time()); |
variable_set('notify_send_last', time()); |
| 80 |
} |
} |
| 106 |
$items = array(); |
$items = array(); |
| 107 |
|
|
| 108 |
if ($may_cache) { |
if ($may_cache) { |
| 109 |
if ($user->uid) { // Do not show this on user/0/notify (see #157850!!) |
$items[] = array('path' => "user/$user->uid/notify", |
| 110 |
$items[] = array('path' => "user/$user->uid/notify", |
'title' => t('My notification settings'), |
| 111 |
'title' => t('My notification settings'), |
'callback' => 'drupal_get_form', |
| 112 |
'callback' => 'drupal_get_form', |
'callback arguments' => array('notify_user_settings_form', $user->uid), |
| 113 |
'callback arguments' => array('notify_user_settings_form', $user->uid), |
'access' => user_access('access notify'), |
| 114 |
'access' => user_access('access notify'), |
'type' => MENU_LOCAL_TASK, |
| 115 |
'type' => MENU_LOCAL_TASK, |
); |
|
); |
|
|
} |
|
| 116 |
$items[] = array('path' => 'admin/user/user/notify', |
$items[] = array('path' => 'admin/user/user/notify', |
| 117 |
'title' => t('Notifications'), |
'title' => t('Notifications'), |
| 118 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 120 |
'access' => user_access('administer notify'), |
'access' => user_access('administer notify'), |
| 121 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 122 |
); |
); |
| 123 |
$items[] = array('path' => 'admin/settings/notify', |
$items[] = array('path' => 'admin/content/notify', |
| 124 |
'title' => t('Notification settings'), |
'title' => t('Notification settings'), |
| 125 |
'description' => t('Adjust settings for new content notifications sent by e-mail.'), |
'description' => t('Adjust settings for new content notifications sent by e-mail.'), |
| 126 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 153 |
*/ |
*/ |
| 154 |
function notify_user_settings_form($uid = 0) { |
function notify_user_settings_form($uid = 0) { |
| 155 |
global $user; |
global $user; |
| 156 |
|
if ($user->uid != $uid && $user->uid != 1) { |
| 157 |
|
drupal_access_denied(); |
| 158 |
|
return; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
$account = user_load(array('uid' => $uid)); |
$account = user_load(array('uid' => $uid)); |
| 162 |
if ($account === FALSE) { |
if (!is_object($account)) { |
| 163 |
drupal_not_found(); |
drupal_not_found(); |
| 164 |
return; |
return; |
| 165 |
} |
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
$result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid); |
$result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid); |
| 169 |
$notify = db_fetch_object($result); |
$notify = db_fetch_object($result); |
| 170 |
$form = array(); |
$form = array(); |
| 171 |
if ($notify->mail) { |
if (!$notify->mail) { |
| 172 |
$form['notify_page_master'] = array('#type' => 'fieldset', '#title' => t('Master switch')); |
drupal_set_message(t('Your e-mail address must be specified on your <a href="@url">my account</a> page.', array('@url' => url('user/'. $account->uid .'/edit'))), 'error'); |
|
$form['notify_page_master']['status'] = array('#type' => 'radios', |
|
|
'#title' => t('Notify status'), |
|
|
'#default_value' => $notify->status, |
|
|
'#options' => array(t('Disabled'), t('Enabled')), |
|
|
'#description' => t('Do you wish to receive periodic e-mails when new content is posted?'), |
|
|
); |
|
|
|
|
|
$form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings')); |
|
|
$form['notify_page_detailed']['node'] = array('#type' => 'radios', |
|
|
'#title' => t('Notify new content'), |
|
|
'#default_value' => $notify->node, |
|
|
'#options' => array(t('Disabled'), t('Enabled')), |
|
|
'#description' => t('Include new content in the notification mail.'), |
|
|
); |
|
|
$form['notify_page_detailed']['teasers'] = array('#type' => 'radios', |
|
|
'#title' => t('Content'), |
|
|
'#default_value' => $notify->teasers, |
|
|
'#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), |
|
|
'#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'), |
|
|
); |
|
|
$form['notify_page_detailed']['comment'] = array('#type' => 'radios', |
|
|
'#title' => t('Notify new comments'), |
|
|
'#default_value' => $notify->comment, |
|
|
'#options' => array(t('Disabled'), t('Enabled')), |
|
|
'#description' => t('Include new comments in the notification mail.'), |
|
|
); |
|
|
$form['uid'] = array('#type' => 'value', '#value' => $account->uid); |
|
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Your e-mail address must be specified on your <a href="@url">my account</a> page.', array('@url' => url('user/'. $notify->uid .'/edit'))), 'error'); |
|
| 173 |
} |
} |
| 174 |
|
|
| 175 |
|
$form['notify_page_master'] = array('#type' => 'fieldset', '#title' => t('Master switch')); |
| 176 |
|
$form['notify_page_master']['status'] = array('#type' => 'radios', |
| 177 |
|
'#title' => t('Notify status'), |
| 178 |
|
'#default_value' => $notify->status, |
| 179 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 180 |
|
'#description' => t('Do you wish to receive periodic e-mails when new content is posted?'), |
| 181 |
|
); |
| 182 |
|
|
| 183 |
|
$form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings')); |
| 184 |
|
$form['notify_page_detailed']['node'] = array('#type' => 'radios', |
| 185 |
|
'#title' => t('Notify new content'), |
| 186 |
|
'#default_value' => $notify->node, |
| 187 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 188 |
|
'#description' => t('Include new content in the notification mail.'), |
| 189 |
|
); |
| 190 |
|
$form['notify_page_detailed']['teasers'] = array('#type' => 'radios', |
| 191 |
|
'#title' => t('Content'), |
| 192 |
|
'#default_value' => $notify->teasers, |
| 193 |
|
'#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), |
| 194 |
|
'#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'), |
| 195 |
|
); |
| 196 |
|
$form['notify_page_detailed']['comment'] = array('#type' => 'radios', |
| 197 |
|
'#title' => t('Notify new comments'), |
| 198 |
|
'#default_value' => $notify->comment, |
| 199 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 200 |
|
'#description' => t('Include new comments in the notification mail.'), |
| 201 |
|
); |
| 202 |
|
$form['uid'] = array('#type' => 'value', '#value' => $account->uid); |
| 203 |
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); |
| 204 |
|
|
| 205 |
return $form; |
return $form; |
| 206 |
} |
} |
| 207 |
|
|
| 260 |
variable_set('notify_send_last', time()); |
variable_set('notify_send_last', time()); |
| 261 |
|
|
| 262 |
if ($num_sent > 0) { |
if ($num_sent > 0) { |
| 263 |
drupal_set_message(t('@count pending notification e-mails have been sent.', array('@count' => $num_sent))); |
drupal_set_message(t('!count pending notification e-mails have been sent.', array('!count' => $num_sent))); |
| 264 |
} |
} |
| 265 |
elseif ($num_failed > 0) { |
elseif ($num_failed > 0) { |
| 266 |
drupal_set_message(t('@count notification e-mails could not be sent.', array('@count' => $num_failed)), 'error'); |
drupal_set_message(t('!count notification e-mails could not be sent.', array('!count' => $num_failed)), 'error'); |
| 267 |
} |
} |
| 268 |
else { |
else { |
| 269 |
drupal_set_message(t('No notification e-mails needed to be sent.')); |
drupal_set_message(t('No notification e-mails needed to be sent.')); |
| 329 |
} |
} |
| 330 |
|
|
| 331 |
/** |
/** |
| 332 |
|
* Format HTML version of outgoing mail |
| 333 |
|
*/ |
| 334 |
|
function _notify_content_html ($node, $notify) { |
| 335 |
|
|
| 336 |
|
switch ($notify->teasers) { |
| 337 |
|
case 0: |
| 338 |
|
return; |
| 339 |
|
case 1: |
| 340 |
|
return check_markup($node->teaser, $node->format, FALSE); |
| 341 |
|
break; |
| 342 |
|
case 2: |
| 343 |
|
return check_markup($node->body, $node->format, FALSE); |
| 344 |
|
} |
| 345 |
|
|
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
/** |
| 349 |
* Helper function to send the notification email. |
* Helper function to send the notification email. |
| 350 |
* |
* |
| 351 |
* TODO: Needs some cleanup and themability. |
* TODO: Needs some cleanup and themability. |
| 406 |
if ($node_count > 0) { |
if ($node_count > 0) { |
| 407 |
$node_body .= $mini_separator ."\n\n"; |
$node_body .= $mini_separator ."\n\n"; |
| 408 |
} |
} |
| 409 |
$node_body .= ++$node_count .'. '. t('@title', array('@title' => $node->title)) ."\n"; |
$node_body .= ++$node_count .'. '. $node->title ."\n"; |
| 410 |
$node_body .= t('@status @type by @author', array('@status' => $status, '@type' => node_get_types('name', $node), '@author' => ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')))) ."\n"; |
$node_body .= t('!status !type by !author', array('!status' => $status, '!type' => node_get_types('name', $node), '!author' => ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')))) ."\n"; |
| 411 |
$node_body .= '[ '. url('node/'. $node->nid, NULL, NULL, TRUE) ." ]\n\n"; |
$node_body .= '[ '. url('node/'. $node->nid, NULL, NULL, TRUE) ." ]\n\n"; |
| 412 |
$node_body .= _notify_content($node, $user) ."\n"; |
$node_body .= _notify_content($node, $user) ."\n"; |
| 413 |
} |
} |
| 415 |
// Prepend node e-mail header as long as user could access at least one node. |
// Prepend node e-mail header as long as user could access at least one node. |
| 416 |
if ($node_count > 0) { |
if ($node_count > 0) { |
| 417 |
$node_body = $separator ."\n" |
$node_body = $separator ."\n" |
| 418 |
. t('Recent content - @count', array('@count' => format_plural(count($nodes), '1 new post', '@count new posts'))) ."\n" |
. t('Recent content - !count', array('!count' => format_plural(count($nodes), '1 new post', '!count new posts'))) ."\n" |
| 419 |
. $separator ."\n\n". $node_body; |
. $separator ."\n\n". $node_body; |
| 420 |
} |
} |
| 421 |
} |
} |
| 438 |
if ($comment_body) { |
if ($comment_body) { |
| 439 |
$comment_body .= $mini_separator ."\n\n"; |
$comment_body .= $mini_separator ."\n\n"; |
| 440 |
} |
} |
| 441 |
$comment_body .= t('@count attached to @type posted by @author: @title', array('@count' => format_plural(count($comment), '1 new comment', '@count new comments'), '@title' => $nodes[$nid]->title, '@type' => node_get_types('name', $nodes[$nid]), '@author' => $nodes[$nid]->name ? $nodes[$nid]->name : variable_get('anonymous', 'Anonymous'))) ."\n"; |
$comment_body .= t('!count attached to !type posted by !author: !title', array('!count' => format_plural(count($comment), '1 new comment', '!count new comments'), '!title' => $nodes[$nid]->title, '!type' => node_get_types('name', $nodes[$nid]), '!author' => $nodes[$nid]->name ? $nodes[$nid]->name : variable_get('anonymous', 'Anonymous'))) ."\n"; |
| 442 |
|
|
| 443 |
$comment_count = 0; |
$comment_count = 0; |
| 444 |
foreach ($comment as $c) { |
foreach ($comment as $c) { |
| 445 |
$comment_body .= ' '. ++$comment_count .'. '. t('@title by @author', array('@title' => $c->subject, '@author' => ($c->name ? $c->name : variable_get(anonymous, 'Anonymous')))) ."\n" |
$comment_body .= ' '. ++$comment_count .'. '. t('!title by !author', array('!title' => $c->subject, '!author' => ($c->name ? $c->name : variable_get(anonymous, 'Anonymous')))) ."\n" |
| 446 |
.' '. url('node/'. $nid, NULL, 'comment-'. $c->cid, TRUE) ."\n\n"; |
.' '. url('node/'. $nid, NULL, 'comment-'. $c->cid, TRUE) ."\n\n"; |
| 447 |
$total_comment_count++; |
$total_comment_count++; |
| 448 |
} |
} |
| 450 |
|
|
| 451 |
if ($total_comment_count > 0) { |
if ($total_comment_count > 0) { |
| 452 |
$comment_body = $separator ."\n" |
$comment_body = $separator ."\n" |
| 453 |
. t('Recent comments - @count', array('@count' => format_plural($total_comment_count, '1 new comment', '@count new comments'))) ."\n" |
. t('Recent comments - !count', array('!count' => format_plural($total_comment_count, '1 new comment', '!count new comments'))) ."\n" |
| 454 |
. $separator ."\n\n". $comment_body; |
. $separator ."\n\n". $comment_body; |
| 455 |
} |
} |
| 456 |
} |
} |
| 462 |
// Set up initial values for e-mail. |
// Set up initial values for e-mail. |
| 463 |
$from = variable_get('site_mail', ini_get('sendmail_from')); |
$from = variable_get('site_mail', ini_get('sendmail_from')); |
| 464 |
$from_name = variable_get('site_name', 'Drupal'); |
$from_name = variable_get('site_name', 'Drupal'); |
| 465 |
$subject = t('@sitename new content notification for @username', array('@username' => $user->name, '@sitename' => variable_get('site_name', 'Drupal'))); |
$subject = t('!sitename new content notification for !username', array('!username' => $user->name, '!sitename' => variable_get('site_name', 'Drupal'))); |
| 466 |
|
|
| 467 |
$body = t('Greetings @user,', array('@user' => $user->name)) ."\n\n". $body; |
$body = t('Greetings !user,', array('!user' => $user->name)) ."\n\n". $body; |
| 468 |
|
|
| 469 |
$body .= "\n-- \n"; |
$body .= "\n-- \n"; |
| 470 |
$body .= t('This is an automatic e-mail from @sitename.', array('@sitename' => variable_get('site_name', 'Drupal')))."\n"; |
$body .= t('This is an automatic e-mail from !sitename.', array('!sitename' => variable_get('site_name', 'Drupal')))."\n"; |
| 471 |
$body .= t('To stop receiving these e-mails, change your notification preferences at @notify-url', array('@notify-url' => url("user/$user->uid/notify" , NULL, NULL, TRUE)))."\n"; |
$body .= t('To stop receiving these e-mails, change your notification preferences at !notify-url', array('!notify-url' => url("user/$user->uid/notify" , NULL, NULL, TRUE)))."\n"; |
| 472 |
|
|
| 473 |
$headers = array();//'From' => "$from_name <$from>"); |
$headers = array();//'From' => "$from_name <$from>"); |
| 474 |
if (!drupal_mail('notify_mail', $user->mail, $subject, wordwrap($body, 72), $from, $headers)) { |
if (!drupal_mail('notify_mail', $user->mail, $subject, wordwrap($body, 72), $from, $headers)) { |
| 529 |
function _notify_mail_urls($url = 0) { |
function _notify_mail_urls($url = 0) { |
| 530 |
static $urls = array(); |
static $urls = array(); |
| 531 |
if ($url) { |
if ($url) { |
| 532 |
$urls[] = strpos($url, '://') ? $url : url($url, NULL, NULL, 1); |
if (strpos($url, '://')) { |
| 533 |
|
$urls[] = $url; |
| 534 |
|
} elseif (strpos($url, '/')==0) { |
| 535 |
|
$urls[] = url(substr($url,1) , NULL, NULL, TRUE); |
| 536 |
|
} else { |
| 537 |
|
$urls[] = url($url, NULL, NULL, TRUE); |
| 538 |
|
} |
| 539 |
return count($urls); |
return count($urls); |
| 540 |
} |
} |
| 541 |
return $urls; |
return $urls; |
| 557 |
static $orig_user = array(); |
static $orig_user = array(); |
| 558 |
|
|
| 559 |
if (isset($uid)) { |
if (isset($uid)) { |
| 560 |
|
// Should a user visit cron.php, or should this module be invoked via |
| 561 |
|
// poormanscron and _notify_send() does not complete, |
| 562 |
|
// the visitor will end up logged in as the "switched to user" for |
| 563 |
|
// subsequent requests unless we disable saving the session |
| 564 |
|
// until we are sure we're the invoking user again. |
| 565 |
|
session_save_session(FALSE); |
| 566 |
$user = user_load(array('uid' => $uid)); |
$user = user_load(array('uid' => $uid)); |
| 567 |
} |
} |
| 568 |
// Retrieve the initial user, can be called multiple times. |
// Retrieve the initial user, can be called multiple times. |
| 569 |
else if (count($orig_user)) { |
else if (count($orig_user)) { |
| 570 |
$user = array_shift($orig_user); |
$user = array_shift($orig_user); |
| 571 |
array_unshift($orig_user, $user); |
array_unshift($orig_user, $user); |
| 572 |
|
session_save_session(TRUE); |
| 573 |
} |
} |
| 574 |
// Store the initial user. |
// Store the initial user. |
| 575 |
else { |
else { |