| 1 |
<?php |
<?php |
| 2 |
// $Id: notify.module,v 2.68.2.11 2008/10/02 21:22:38 matt2000 Exp $ |
// $Id: notify.module,v 2.68.2.12 2008/11/08 19:38:55 matt2000 Exp $ |
| 3 |
|
|
| 4 |
define('NOTIFY_NODE_TYPE', 'notify_node_type_'); |
define('NOTIFY_NODE_TYPE', 'notify_node_type_'); |
| 5 |
|
|
| 51 |
'#title' => 'Send notifications every', |
'#title' => 'Send notifications every', |
| 52 |
'#default_value' => variable_get('notify_send', array(86400)), |
'#default_value' => variable_get('notify_send', array(86400)), |
| 53 |
'#options' => $period, |
'#options' => $period, |
| 54 |
'#description' => 'How often should new content notifications be sent? Requires cron to be running.', |
'#description' => 'How often should new content notifications be sent? Requires cron to be running at least this often.', |
| 55 |
|
); |
| 56 |
|
|
| 57 |
|
$form['notify_settings']['notify_send_hour'] = array( |
| 58 |
|
'#type' => 'select', |
| 59 |
|
'#title' => 'Hour to Send Notifications', |
| 60 |
|
'#description' => 'Specify the hour (24-hour clock) in which notifications should be sent, if the frequency is one day or greater.', |
| 61 |
|
'#default_value' => variable_get('notify_send_hour', 9), |
| 62 |
|
'#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), |
| 63 |
); |
); |
| 64 |
|
|
| 65 |
$form['notify_settings']['notify_attempts'] = array( |
$form['notify_settings']['notify_attempts'] = array( |
| 68 |
'#default_value' => variable_get('notify_attempts', array(5)), |
'#default_value' => variable_get('notify_attempts', array(5)), |
| 69 |
'#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20), |
'#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20), |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
$set = 'ntype'; |
$set = 'ntype'; |
| 73 |
$form[$set] = array( |
$form[$set] = array( |
| 74 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 96 |
function notify_cron() { |
function notify_cron() { |
| 97 |
$send_last = variable_get('notify_send_last', 0); |
$send_last = variable_get('notify_send_last', 0); |
| 98 |
$send_interval = variable_get('notify_send', 86400); |
$send_interval = variable_get('notify_send', 86400); |
| 99 |
$send_hour = variable_get('notify_send_hour', date('G', variable_get('notify_send_last', 0))); |
$send_hour = variable_get('notify_send_hour', 9); |
| 100 |
if ( (time() - $send_last > $send_interval) |
if ( (time() - $send_last > $send_interval) |
| 101 |
&& (date('G', time()) > $send_hour) |
&& (date('G', time()) >= $send_hour || $send_interval < 86400) |
| 102 |
&& ($send_interval != -1) //special case of settings to send 'never' |
&& ($send_interval != -1) //special case of settings to send 'never' |
| 103 |
) { |
) { |
| 104 |
_notify_send(); |
_notify_send(); |
| 548 |
} |
} |
| 549 |
|
|
| 550 |
/** |
/** |
| 551 |
* Switch from original user to mail submision user and back. |
* Switch from original user to mail submission user and back. |
| 552 |
* |
* |
| 553 |
* NOTE: Copied from mailhandler |
* NOTE: Copied from mailhandler |
| 554 |
* |
* |
| 563 |
static $orig_user = array(); |
static $orig_user = array(); |
| 564 |
|
|
| 565 |
if (isset($uid)) { |
if (isset($uid)) { |
| 566 |
|
// Should a user visit cron.php, or should this module be invoked via poormanscron and _notify_send() does not complete, |
| 567 |
|
// the visitor will end up logged in as the "switched to user" for subsequent requests unless we disable saving the session |
| 568 |
|
// until we are sure we're the invoking user again. |
| 569 |
|
session_save_session(FALSE); |
| 570 |
$user = user_load(array('uid' => $uid)); |
$user = user_load(array('uid' => $uid)); |
| 571 |
} |
} |
| 572 |
// Retrieve the initial user, can be called multiple times. |
// Retrieve the initial user, can be called multiple times. |
| 573 |
else if (count($orig_user)) { |
else if (count($orig_user)) { |
| 574 |
$user = array_shift($orig_user); |
$user = array_shift($orig_user); |
| 575 |
array_unshift($orig_user, $user); |
array_unshift($orig_user, $user); |
| 576 |
|
session_save_session(TRUE); |
| 577 |
} |
} |
| 578 |
// Store the initial user. |
// Store the initial user. |
| 579 |
else { |
else { |