/[drupal]/contributions/modules/notify/notify.module
ViewVC logotype

Diff of /contributions/modules/notify/notify.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 2.73, Wed Jan 14 01:10:53 2009 UTC revision 2.74, Tue Feb 3 01:52:57 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: notify.module,v 2.72 2008/08/30 14:44:49 matt2000 Exp $  // $Id: notify.module,v 2.68.2.13 2008/12/17 22:00:06 matt2000 Exp $
3    
4    define('NOTIFY_NODE_TYPE', 'notify_node_type_');
5    
6  /**  /**
7   * Implementation of hook_help().   * Implementation of hook_help().
# Line 33  function notify_admin_settings() { Line 35  function notify_admin_settings() {
35      604800      => format_interval(604800),      604800      => format_interval(604800),
36      1209600     => format_interval(1209600),      1209600     => format_interval(1209600),
37      2419200     => format_interval(2419200),      2419200     => format_interval(2419200),
38      -1          => t('Never'),      -1          => t('Never'),
39    );    );
40    
41    $form = array();    $form = array();
42    
43    $form['notify_send'] = array(    $form['notify_settings'] = array(
44        '#type' => 'fieldset',
45        '#title' => t('E-mail notification settings'),
46        '#collapsible' => TRUE,
47      );
48    
49      $form['notify_settings']['notify_send'] = array(
50      '#type' => 'select',      '#type' => 'select',
51      '#title' => t('Send notifications every'),      '#title' => 'Send notifications every',
52      '#default_value' => variable_get('notify_send', 86400),      '#default_value' => variable_get('notify_send', array(86400)),
53      '#options' => $period,      '#options' => $period,
54      '#description' => t('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_send_hour'] = array(    $form['notify_settings']['notify_send_hour'] = array(
58      '#type' => 'select',      '#type' => 'select',
59      '#title' => t('Send notifications during this hour'),      '#title' => 'Hour to Send Notifications',
60      '#default_value' => variable_get('notify_send_hour', date('G', variable_get('notify_send_last', 0))),      '#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),      '#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),
     '#description' => t('Hour of the day to send noticiations, on 24 hour clock.'),  
63    );    );
64    
65    $form['notify_attempts'] = array(    $form['notify_settings']['notify_attempts'] = array(
66      '#type' => 'select',      '#type' => 'select',
67      '#title' => t('Number of failed sends after which notifications are disabled'),      '#title' => 'Number of failed sends after which notifications are disabled',
68      '#default_value' => variable_get('notify_attempts', 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';
73      $form[$set] = array(
74        '#type' => 'fieldset',
75        '#title' => 'Notification by node type',
76        '#collapsible' => true,
77        '#collapsed' => false,
78        '#description' => 'Having nothing checked defaults to sending notifications about all node types.'
79      );
80    
81      foreach (node_get_types('types', array()) as $type => $object) {
82        $form[$set][NOTIFY_NODE_TYPE . $type] = array(
83          '#type' => 'checkbox',
84          '#title' => $object->name,
85          '#return_value' => 1,
86          '#default_value' => variable_get(NOTIFY_NODE_TYPE . $type, 0),
87        );
88      }
89    
90    return system_settings_form($form);    return system_settings_form($form);
91  }  }
# Line 70  function notify_admin_settings() { Line 96  function notify_admin_settings() {
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();
# Line 88  function notify_user($type, &$edit, &$us Line 114  function notify_user($type, &$edit, &$us
114      case 'delete':      case 'delete':
115        db_query('DELETE FROM {notify} WHERE uid = %d', $user->uid);        db_query('DELETE FROM {notify} WHERE uid = %d', $user->uid);
116        break;        break;
117    
118        case 'register':
119          return _notify_user_reg_fields();
120          break;
121    
122        case 'insert':
123          if (isset($edit['notify_decision']) && $edit['notify_decision'] == 1){
124            db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $user->uid, 1, 1, 0, 0);
125            $edit['notify_decision'] = NULL;
126          }
127          break;
128    
129    }    }
130  }  }
131    
132    
133    /**
134     * Returns form fields to be added to User Regsitration form
135     */
136    function _notify_user_reg_fields() {
137      // Get the variable for how often the notifications are sent out
138      $period = variable_get("notify_send", 86400);
139    
140      // Add a fieldset containing a checkbox for users to accept
141      // getting updates on the registration form.
142      $fields['notify_agree'] = array(
143        '#type' => 'fieldset',
144        '#title' => t('Daily Email News Notifications')
145      );
146    
147      // Add the checkbox to the fieldset
148      $fields['notify_agree']['notify_decision'] = array(
149        '#type' => 'checkbox',
150        '#title' => t('Receive email notifications of news posted to this site. Notifications are sent every ' . format_interval($period).'.'),
151        '#return_value' => 1,
152        '#default_value' => 1,
153        '#description' => t('By accepting to receive <em>daily email news notifications</em>, you will be kept informed of news associated with ' . variable_get('site_name', 'Drupal') . '.')
154      );
155    
156      return $fields;
157    }
158    
159    
160  /**  /**
161   * Implementation of hook_perm().   * Implementation of hook_perm().
162   */   */
# Line 100  function notify_perm() { Line 166  function notify_perm() {
166    
167  /**  /**
168   * Implementation of hook_menu().   * Implementation of hook_menu().
169     *
170     * @return array
171   */   */
172  function notify_menu($may_cache) {  function notify_menu() {
   global $user;  
173    $items = array();    $items = array();
174    
175    if ($may_cache) {    $items['admin/settings/notify'] = array(
176      $items[] = array('path' => "user/$user->uid/notify",      'title' => 'Notification settings',
177        'title' => t('My notification settings'),      'description' => 'Adjust settings for new content notifications sent by e-mail.',
178        'callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
179        'callback arguments' => array('notify_user_settings_form', $user->uid),      'page arguments' => array('notify_admin_settings'),
180        'access' => user_access('access notify'),      'access callback' => 'user_access',
181        'type' => MENU_LOCAL_TASK,      'access arguments' => array('administer notify'),
182      );      'type' => MENU_NORMAL_ITEM,
183      $items[] = array('path' => 'admin/user/user/notify',    );
184        'title' => t('Notifications'),    $items['user/%user/notify'] = array(
185        'callback' => 'drupal_get_form',      'title' => 'Notification settings',
186        'callback arguments' => 'notify_admin_users',      'page callback' => 'drupal_get_form',
187        'access' => user_access('administer notify'),      'page arguments' => array('notify_user_settings_form', 1),
188        'type' => MENU_LOCAL_TASK,      'access callback' => 'user_access',
189      );      'access arguments' => array('access notify'),
190      $items[] = array('path' => 'admin/content/notify',      'type' => MENU_LOCAL_TASK
191        'title' => t('Notification settings'),    );
192        'description' => t('Adjust settings for new content notifications sent by e-mail.'),    $items['admin/user/user/notify'] = array(
193        'callback' => 'drupal_get_form',      'title' => 'Notifications',
194        'callback arguments' => 'notify_admin_settings',      'page callback' => 'drupal_get_form',
195        'access' => user_access('administer notify'),      'page arguments' => array('notify_admin_users'),
196        'type' => MENU_NORMAL_ITEM,      'access callback' => 'user_access',
197      );      'access arguments' => array('administer notify'),
198    }      'type' => MENU_LOCAL_TASK,
199    else {    );
     if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != $user->uid) {  
       $account = user_load(array('uid' => arg(1)));  
       if ($account->uid) {  
         $items[] = array(  
           'path' => 'user/'. $account->uid .'/notify',  
           'title' => t('Notification settings'),  
           'callback' => 'drupal_get_form',  
           'callback arguments' => array('notify_user_settings_form', arg(1)),  
           'access' => user_access('administer notify'),  
           'type' => MENU_LOCAL_TASK,  
         );  
       }  
     }  
   }  
200    
201    return $items;    return $items;
202  }  }
203    
204      /**
205      * Register the themeing the form data into a table at
206      * admin/user/user/notify
207      *
208      * @return array
209      */
210      function notify_theme() {
211        return array(
212          'notify_admin_users' => array(
213          'arguments' => array('form' => NULL)
214        )
215      );
216    }
217    
218  /**  /**
219   * Menu callback; show user notification options.   * Menu callback; show user notification options.
220   */   */
221  function notify_user_settings_form($uid = 0) {  function notify_user_settings_form(&$form_state, $arg) {
222    global $user;    global $user;
223    if ($user->uid != $arg->uid && $user->uid != 1) {    if ($user->uid != $arg->uid && $user->uid != 1) {
224      drupal_access_denied();      drupal_access_denied();
# Line 164  function notify_user_settings_form($uid Line 231  function notify_user_settings_form($uid
231      return;      return;
232    }    }
233    
   
234    $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);
235    $notify = db_fetch_object($result);    $notify = db_fetch_object($result);
236    $form = array();    $form = array();
# Line 172  function notify_user_settings_form($uid Line 238  function notify_user_settings_form($uid
238          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');          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');
239    }    }
240    
241    $form['notify_page_master'] = array('#type' => 'fieldset', '#title' => t('Master switch'));    $form['notify_page_master'] = array('#type' => 'fieldset', '#title' => 'Master switch');
242    $form['notify_page_master']['status'] = array('#type' => 'radios',    $form['notify_page_master']['status'] = array('#type' => 'radios',
243      '#title' => t('Notify status'),      '#title' => 'Notify status',
244      '#default_value' => $notify->status,      '#default_value' => $notify->status,
245      '#options' =>  array(t('Disabled'), t('Enabled')),      '#options' =>  array(t('Disabled'), t('Enabled')),
246      '#description' => t('Do you wish to receive periodic e-mails when new content is posted?'),      '#description' => t('Do you wish to receive periodic e-mails when new content is posted?'),
# Line 182  function notify_user_settings_form($uid Line 248  function notify_user_settings_form($uid
248    
249    $form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings'));    $form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings'));
250    $form['notify_page_detailed']['node'] = array('#type' => 'radios',    $form['notify_page_detailed']['node'] = array('#type' => 'radios',
251      '#title' => t('Notify new content'),      '#title' => 'Notify new content',
252      '#default_value' => $notify->node,      '#default_value' => $notify->node,
253      '#options' => array(t('Disabled'), t('Enabled')),      '#options' => array(t('Disabled'), t('Enabled')),
254      '#description' => t('Include new content in the notification mail.'),      '#description' => t('Include new content in the notification mail.'),
255    );    );
256    $form['notify_page_detailed']['teasers'] = array('#type' => 'radios',    $form['notify_page_detailed']['teasers'] = array('#type' => 'radios',
257      '#title' => t('Content'),      '#title' => 'Content',
258      '#default_value' => $notify->teasers,      '#default_value' => $notify->teasers,
259      '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')),      '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')),
260      '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'),      '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'),
# Line 205  function notify_user_settings_form($uid Line 271  function notify_user_settings_form($uid
271    return $form;    return $form;
272  }  }
273    
274  function notify_user_settings_form_submit($form_id, $form_values) {  function notify_user_settings_form_submit($form, &$form_state) {
275    db_query('DELETE FROM {notify} WHERE uid = %d', $form_values['uid']);    unset($form);
276    db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $form_values['uid'], $form_values['status'], $form_values['node'], $form_values['teasers'], $form_values['comment']);    db_query('DELETE FROM {notify} WHERE uid = %d', $form_state['values']['uid']);
277      db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $form_state['values']['uid'], $form_state['values']['status'], $form_state['values']['node'], $form_state['values']['teasers'], $form_state['values']['comment']);
278    drupal_set_message(t('Notify settings saved.'));    drupal_set_message(t('Notify settings saved.'));
279  }  }
280    
# Line 229  function notify_admin_users() { Line 296  function notify_admin_users() {
296      $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node);      $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node);
297      $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')));      $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')));
298      $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment);      $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment);
299      $form['users'][$notify->uid]['attempts'] = array('#type' => 'markup', '#value' => $notify->attempts ? intval($notify->attempts) : 0);      $form['users'][$notify->uid]['attempts'] = array('#type' => 'textfield', '#size' => 2,  '#default_value' => $notify->attempts ? intval($notify->attempts) : 0);
300    }    }
301    
302    $form['flush'] = array(    $form['flush'] = array(
# Line 247  function notify_admin_users() { Line 314  function notify_admin_users() {
314  /**  /**
315   * Submit for the notify_admin form.   * Submit for the notify_admin form.
316   */   */
317  function notify_admin_users_submit($form_id, $form_values) {  function notify_admin_users_submit($form, &$form_state) {
318    if ($form_values['users']) {    unset($form);
319      foreach ($form_values['users'] as $uid => $settings) {  
320        db_query('UPDATE {notify} SET node = %d, teasers = %d, comment = %d WHERE uid = %d', $settings['node'], $settings['teasers'], $settings['comment'], $uid);    if ($form_state['values']['users']) {
321        foreach ($form_state['values']['users'] as $uid => $settings) {
322          db_query('UPDATE {notify} SET node = %d, teasers = %d, comment = %d, attempts = %d WHERE uid = %d', $settings['node'], $settings['teasers'], $settings['comment'], $settings['attempts'], $uid);
323      }      }
324    }    }
325    drupal_set_message(t('Notify settings saved.'));    drupal_set_message(t('Notify settings saved.'));
326    
327    if ($form_values['flush']) {    if ($form_state['values']['flush']) {
328      list($num_sent, $num_failed) = _notify_send();      list($num_sent, $num_failed) = _notify_send();
329      variable_set('notify_send_last', time());      variable_set('notify_send_last', time());
330    
# Line 314  function _notify_content($node, $notify) Line 383  function _notify_content($node, $notify)
383        $txt = check_markup($node->body, $node->format, FALSE);        $txt = check_markup($node->body, $node->format, FALSE);
384    }    }
385    
386    $pattern = '@(<a href="(.+?)">(.+?)</a>)@ei';    return drupal_html_to_text($txt);
   $txt = preg_replace($pattern, "'\\3 ['. _notify_mail_urls('\\2') .']'", $txt);  
   $urls = _notify_mail_urls();  
   if (count($urls)) {  
     $txt .= "\n";  
     for ($max = count($urls); $i < $max; $i++) {  
       $txt .= '['. ($i + 1) .'] '. $urls[$i] ."\n";  
     }  
   }  
   $txt = strip_tags($txt);  
   $txt = notify_entities_to_utf8($txt);  
   return wordwrap($txt, 72);  
 }  
   
 /**  
  * Format HTML version of outgoing mail  
  */  
 function _notify_content_html ($node, $notify) {  
   
   switch ($notify->teasers) {  
     case 0:  
       return;  
     case 1:  
       return check_markup($node->teaser, $node->format, FALSE);  
       break;  
     case 2:  
       return check_markup($node->body, $node->format, FALSE);  
   }  
   
387  }  }
388    
389  /**  /**
# Line 360  function _notify_send() { Line 401  function _notify_send() {
401    
402    _notify_switch_user(); // Store current user    _notify_switch_user(); // Store current user
403    
404      // Fetch all node type authorized by notify settings
405      $ntype = array();
406      foreach (node_get_types() as $type => $name) {
407        if (variable_get(NOTIFY_NODE_TYPE . $type, 0)) {
408          $ntype[] = $type;
409        }
410        if (count($ntype) >= 1) {
411          $reqntype = "AND (n.type = '". implode("' OR n.type = '", $ntype) ."') ";
412        }
413        else {
414          $reqntype = '';
415        }
416      }
417    
418    // Fetch users with notify enabled    // Fetch users with notify enabled
419    $uresult = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));    $uresult = db_query('SELECT u.uid, u.name, u.mail, u.language, n.status, n.node, n.teasers, n.comment FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));
420    
421    while ($user = db_fetch_object($uresult)) {    while ($user = db_fetch_object($uresult)) {
422      // Switch current user to this account to use node_access functions, etc.      // Switch current user to this account to use node_access functions, etc.
423      _notify_switch_user($user->uid);      _notify_switch_user($user->uid);
424    
425      // Fetch all new nodes and 'load' it to get proper body, etc.      // Fetch all new nodes and 'load' it to get proper body, etc.
426      $nresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) AND n.created > %d AND n.created <= %d ORDER BY n.created'), $period, time());      $nresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) '. $reqntype . ' AND ((n.created > %d AND n.created <= %d) OR (n.changed > %d AND n.changed <= %d)) ORDER BY n.created'), $period, time(), $period, time());
427      $nodes = array();      $nodes = array();
428      while ($node = db_fetch_object($nresult)) {      while ($node = db_fetch_object($nresult)) {
429        $nodes[$node->nid] = node_load($node->nid);        $nodes[$node->nid] = node_load($node->nid);
430      }      }
431    
432      // Fetch new comments.      // Fetch new comments.
433      $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.name FROM {comments} c WHERE c.status = %d AND c.timestamp > %d AND c.timestamp <= %d ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period, time());      $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = %d AND c.timestamp > %d AND c.timestamp <= %d '. $reqntype . ' ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period, time());
434      $comments = array();      $comments = array();
435      while ($comment = db_fetch_object($cresult)) {      while ($comment = db_fetch_object($cresult)) {
436        $comments[$comment->nid][] = $comment;        $comments[$comment->nid][] = $comment;
# Line 396  function _notify_send() { Line 451  function _notify_send() {
451          }          }
452    
453          // TODO: Add functionality to hook into moderation modules?          // TODO: Add functionality to hook into moderation modules?
454          if ($node->status == 1) {          if ($node->moderate == 1) {
455              $status = t('Queued');
456            }
457            elseif ($node->status == 1) {
458            $status = t('Published');            $status = t('Published');
459          }          }
460          elseif ($node->status == 0) {          elseif ($node->status == 0) {
# Line 408  function _notify_send() { Line 466  function _notify_send() {
466          }          }
467          $node_body .= ++$node_count .'. '. $node->title ."\n";          $node_body .= ++$node_count .'. '. $node->title ."\n";
468          $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";
469          $node_body .= '[ '. url('node/'. $node->nid, NULL, NULL, TRUE) ." ]\n\n";          $node_body .= '[ '. url('node/'. $node->nid, array('absolute' => TRUE)) ." ]\n\n";
470          $node_body .= _notify_content($node, $user) ."\n";          $node_body .= _notify_content($node, $user) ."\n";
471        }        }
472    
473        // 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.
474        if ($node_count > 0) {        if ($node_count > 0) {
475          $node_body = $separator ."\n"          $node_body = $separator ."\n"
476            . 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($nodes) .' new posts'))) ."\n"
477            . $separator ."\n\n". $node_body;            . $separator ."\n\n". $node_body;
478        }        }
479      }      }
# Line 431  function _notify_send() { Line 489  function _notify_send() {
489          }          }
490    
491          // Don't show comments if we're not allowed to view this node.          // Don't show comments if we're not allowed to view this node.
492          if (!node_access('view', $nodes[$nid], $user->uid)) {          if (!node_access('view', $nodes[$nid])) {
493            continue;            continue;
494          }          }
495    
# Line 442  function _notify_send() { Line 500  function _notify_send() {
500    
501          $comment_count = 0;          $comment_count = 0;
502          foreach ($comment as $c) {          foreach ($comment as $c) {
503            $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"
504              .'     '. url('node/'. $nid, NULL, 'comment-'. $c->cid, TRUE) ."\n\n";              .'     '. url('node/'. $nid, array('fragment' => 'comment-'. $c->cid, 'absolute' => TRUE)) ."\n\n";
505            $total_comment_count++;            $total_comment_count++;
506          }          }
507        }        }
# Line 460  function _notify_send() { Line 518  function _notify_send() {
518      // If there was anything new, send mail.      // If there was anything new, send mail.
519      if ($body) {      if ($body) {
520        // Set up initial values for e-mail.        // Set up initial values for e-mail.
       $from = variable_get('site_mail', ini_get('sendmail_from'));  
       $from_name = variable_get('site_name', 'Drupal');  
       $subject = t('!sitename new content notification for !username', array('!username' => $user->name, '!sitename' => variable_get('site_name', 'Drupal')));  
   
       $body = t('Greetings !user,', array('!user' => $user->name)) ."\n\n". $body;  
   
       $body .= "\n-- \n";  
       $body .= t('This is an automatic e-mail from !sitename.', array('!sitename' => variable_get('site_name', 'Drupal')))."\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";  
521    
522        $headers = array();//'From' => "$from_name <$from>");        $headers = array();//'From' => "$from_name <$from>");
523        if (!drupal_mail('notify_mail', $user->mail, $subject, wordwrap($body, 72), $from, $headers)) {        if (!drupal_mail('notify', 'send', $user->mail, user_preferred_language($user), array('content' => wordwrap($body, 72)))) {
524          $num_failed++;          $num_failed++;
525          db_query('UPDATE {notify} SET attempts = attempts + 1 WHERE uid = %d', $user->uid);          db_query('UPDATE {notify} SET attempts = attempts + 1 WHERE uid = %d', $user->uid);
526          watchdog('error', t('Notify: User %name (%mail) could not be notified. Mail error.', array('%name' => $user->name, '%mail' => $user->mail)));          watchdog('notify', 'User %name (%mail) could not be notified. Mail error.', array('%name' => $user->name, '%mail' => $user->mail), WATCHDOG_ERROR);
527        }        }
528        else {        else {
529          $num_sent++;          $num_sent++;
530          watchdog('user', t('Notify: User %name (%mail) notified successfully.', array('%name' => $user->name, '%mail' => $user->mail)));          watchdog('notify', 'User %name (%mail) notified successfully.', array('%name' => $user->name, '%mail' => $user->mail), WATCHDOG_INFO);
531        }        }
532      }      }
533    }    }
# Line 487  function _notify_send() { Line 536  function _notify_send() {
536    return array($num_sent, $num_failed);    return array($num_sent, $num_failed);
537  }  }
538    
539  function notify_entities_to_utf8($text) {  function notify_mail($key, &$message, $params) {
540    static $table;    global $user;
   // We store named entities in a table for quick processing.  
   if (!isset($table)) {  
     // Get all named HTML entities.  
     $table = array_flip(get_html_translation_table(HTML_ENTITIES));  
     // PHP gives us Windows-1252/ISO-8859-1 data, we need UTF-8.  
     $table = array_map('utf8_encode', $table);  
   }  
   $text = strtr($text, $table);  
   
   // Any remaining entities are numerical. Use a regexp to replace them.  
   return preg_replace('/&#(x?)([A-Za-z0-9]+);/e', '_notify_entity_to_utf8("$1", "$2")', $text);  
 }  
   
 function _notify_entity_to_utf8($hex, $codepoint) {  
   if ($hex != '') {  
     $codepoint = base_convert($codepoint, 16, 10);  
   }  
   if ($codepoint < 0x80) {  
     return chr($codepoint);  
   }  
   else if ($codepoint < 0x800) {  
     return chr(0xC0 | ($codepoint >> 6))  
          . chr(0x80 | ($codepoint & 0x3F));  
   }  
   else if ($codepoint < 0x10000) {  
     return chr(0xE0 | ( $codepoint >> 12))  
          . chr(0x80 | (($codepoint >> 6) & 0x3F))  
          . chr(0x80 | ( $codepoint       & 0x3F));  
   }  
   else if ($codepoint < 0x200000) {  
     return chr(0xF0 | ( $codepoint >> 18))  
          . chr(0x80 | (($codepoint >> 12) & 0x3F))  
          . chr(0x80 | (($codepoint >> 6)  & 0x3F))  
          . chr(0x80 | ( $codepoint        & 0x3F));  
   }  
 }  
541    
542  function _notify_mail_urls($url = 0) {    $message['subject'] = t('!sitename new content notification for !username', array('!username' => $user->name, '!sitename' => variable_get('site_name', 'Drupal')));
543    static $urls = array();    $message['body'] = t('Greetings !user,', array('!user' => $user->name)) ."\n\n";
544    if ($url) {    $message['body'] .= $params['content'];
545      if (strpos($url, '://')) {    $message['body'] .= "\n-- \n";
546        $urls[] = $url;    $message['body'] .= t('This is an automatic e-mail from !sitename.', array('!sitename' => variable_get('site_name', 'Drupal'))) ."\n";
547      } elseif (strpos($url, '/')==0) {    $message['body'] .= t('To stop receiving these e-mails, change your notification preferences at !notify-url', array('!notify-url' => url("user/$user->uid/notify" , array('absolute' => TRUE)))) ."\n";
       $urls[] = url(substr($url,1) , NULL, NULL, TRUE);  
     } else {  
       $urls[] = url($url, NULL, NULL, TRUE);  
     }  
     return count($urls);  
   }  
   return $urls;  
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   *   *
# Line 557  function _notify_switch_user($uid = NULL Line 563  function _notify_switch_user($uid = NULL
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      // Should a user visit cron.php, or should this module be invoked via poormanscron and _notify_send() does not complete,
567      // poormanscron and _notify_send() does not complete,      // the visitor will end up logged in as the "switched to user" for subsequent requests unless we disable saving the session
     // 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.      // until we are sure we're the invoking user again.
569      session_save_session(FALSE);      session_save_session(FALSE);
570      $user = user_load(array('uid' => $uid));      $user = user_load(array('uid' => $uid));

Legend:
Removed from v.2.73  
changed lines
  Added in v.2.74

  ViewVC Help
Powered by ViewVC 1.1.2