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

Diff of /contributions/modules/comment_subscribe/comment_subscribe.module

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

revision 1.2.2.5, Sat Jan 10 09:49:30 2009 UTC revision 1.2.2.6, Fri Jan 30 07:46:35 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: comment_subscribe.module,v 1.2.2.4 2008/12/27 05:44:52 zyxware Exp $  // $Id: comment_subscribe.module,v 1.2.2.1 2008/07/28 09:31:25 zyxware Exp $
3    
4  /**  /**
5   * @file   * @file
6   *   * This module provides comment followup e-mail notification for
  * This module provides comment followup e-mail notification for  
7   * anonymous as well as registered users.   * anonymous as well as registered users.
8   */   */
9  //The mail to be send for the users  //The mail to be send for the users
10  define('DEFAULT_MAILTEXT','  define('DEFAULT_MAILTEXT', '
11  Hi !name,  Hi !name,
12    
13  !commname has commented on: "!node_title"  !commname has commented on: "!node_title"
# Line 19  The post is about Line 18  The post is about
18  ----  ----
19    
20  You can view the comment at the following url  You can view the comment at the following url
21  !comment_url  !comment_urlYou can stop receiving emails when someone replies to this blog post,
   
 You can stop receiving emails when someone replies to this blog post,  
22  by going to !link1  by going to !link1
23    
24  You can stop receiving emails when someone replies to your comment,  You can stop receiving emails when someone replies to your comment,
# Line 32  If you have an account at the site and i Line 29  If you have an account at the site and i
29    
30  Thanks for your feedback,  Thanks for your feedback,
31    
32  Webmaster of !site  Webmaster of !site
33  !mission  !mission
34  !uri  !uri
35  ');  ');
36  //The mail to be send for the author  //The mail to be send for the author
37  define('DEFAULT_AUTHOR_MAILTEXT', '  define('DEFAULT_AUTHOR_MAILTEXT', '
# Line 61  Webmaster of !site Line 58  Webmaster of !site
58  function comment_subscribe_help($path, $arg) {  function comment_subscribe_help($path, $arg) {
59    switch ( $path ) {    switch ( $path ) {
60      case 'admin/modules#description':      case 'admin/modules#description':
61        return t('Comment follow-up e-mail notification for anonymous as well as registered users.');      return t('Comment follow-up e-mail notification for anonymous as well as registered users.');
62        break;      break;
63    }    }
64  }  }
65  /**  /**
# Line 74  function comment_subscribe_menu() { Line 71  function comment_subscribe_menu() {
71    $items['admin/content/comment_subscribe'] = array(    $items['admin/content/comment_subscribe'] = array(
72      'title' => t('Comment Subscribe'),      'title' => t('Comment Subscribe'),
73      'description' => t('Comment follow-up mail subscription.'),      'description' => t('Comment follow-up mail subscription.'),
74       'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
75      'page arguments' => array('comment_subscribe_settings'),      'page arguments' => array('comment_subscribe_settings'),
76      'access arguments' => array('administer comment_subscribe'),      'access arguments' => array('administer comment_subscribe'),
77      'type' => MENU_NORMAL_ITEM,      'type' => MENU_NORMAL_ITEM,
# Line 84  function comment_subscribe_menu() { Line 81  function comment_subscribe_menu() {
81      'title' => t('Comment Subscribe') ,      'title' => t('Comment Subscribe') ,
82      'page callback' => 'comment_subscribe_page',      'page callback' => 'comment_subscribe_page',
83      'access callback' => 'user_access',      'access callback' => 'user_access',
84       'access arguments' => array('disable comments'),      'access arguments' => array('disable comments'),
85      'type' => MENU_CALLBACK      'type' => MENU_CALLBACK
86    );    );
87    return $items;    return $items;
# Line 95  function comment_subscribe_menu() { Line 92  function comment_subscribe_menu() {
92  function comment_subscribe_perm() {  function comment_subscribe_perm() {
93    return array('administer comment_subscribe', 'disable comments');    return array('administer comment_subscribe', 'disable comments');
94  }  }
95  /*  /**
96   *Funtion to save the node subscription flag when an author creates a node   * Funtion to save the node subscription flag when an author creates a node.
97   */   */
98  function comment_subscribe_nodeapi(&$node, $op, $teaser, $page) {  function comment_subscribe_nodeapi(&$node, $op, $teaser, $page) {
99      switch ($op) {
100    switch ( $op ) {      case 'insert':
101       case 'insert':        $sql = "INSERT INTO {z_nodesubscribe} (nid, uid, nodesubscribe) values(%d, %d, %d)";
       $sql = "INSERT INTO {z_nodesubscribe} (nid, uid, nodesubscribe)  
       values(%d, %d, %d)";  
102        db_query($sql, $node->nid, $node->uid, $node->nodesubscribe);        db_query($sql, $node->nid, $node->uid, $node->nodesubscribe);
103       break;      break;
   }  
104    
105      }
106  }  }
107  /**  /**
108   * Insert our checkbox, and populate fields.   * Insert our checkbox, and populate fields.
# Line 119  function comment_subscribe_form_alter(&$ Line 114  function comment_subscribe_form_alter(&$
114    if ( ($form_id == 'comment_form')) {    if ( ($form_id == 'comment_form')) {
115      $op = isset($_POST['op']) ? $_POST['op'] : '';      $op = isset($_POST['op']) ? $_POST['op'] : '';
116      if ($op == t('Preview')) {      if ($op == t('Preview')) {
117         drupal_set_message(t('ATTENTION: your comment is NOT YET posted -        drupal_set_message(t('ATTENTION: your comment is NOT YET posted - please click the post button to confirm your post' ));
118          please click the post button to confirm your post' )        //extra submit button on top.
119         );        if (!form_get_errors() && ((variable_get('comment_preview', COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL)  || ($op == t('Preview')) || ($op == t('Save'))))    {
120         //extra submit button on top          $form['submitextra'] = array(
121         if (!form_get_errors() && ((variable_get('comment_preview',          '#type' => 'fieldset',
122           COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL)          '#title' => t('Comment is not posted yet - please click post button to confirm your post'),
123           || ($op == t('Preview')) || ($op == t('Save'))))     {          '#weight' => -99,
124           $form['submitextra'] = array(          '#collapsible' => FALSE
             '#type' => 'fieldset',  
             '#title' => t('Comment is not posted yet - please click  
             post button to confirm your post'),  
             '#weight' => -99,  
             '#collapsible' => FALSE  
          );  
          $form['submitextra']['submit'] = array('#type' => 'submit',  
           '#value' => t('Save'), '#weight' => -20);  
        }  
     }  
     if(variable_get("comment_subscribe_node_alert",FALSE)) {  
         $form['commentsubscribenode'] = array(  
           '#type' => 'checkbox',  
             '#prefix' => '<div id = "comment_suscribe">',  
         '#suffix' => '</div>',  
           '#title' => t('Email me about all replies to this article.'),  
           '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get  
         ("comment_subscribe_default_anon_mailalert", FALSE)  
125          );          );
126            $form['submitextra']['submit'] = array(
127            '#type' => 'submit',
128            '#value' => t('Save'),
129            '#weight' => -20);
130          }
131        }
132        if (variable_get("comment_subscribe_node_alert", FALSE)) {
133          $form['commentsubscribenode'] = array(
134          '#type' => 'checkbox',
135          '#prefix' => '<div id = "comment_suscribe">',
136          '#suffix' => '</div>',
137          '#title' => t('Email me about all replies to this article.'),
138          '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get
139          ("comment_subscribe_default_node_mailalert", FALSE)
140          );
141      }      }
142      else  if ( ($user->uid == 0) || ( variable_get(      else  if ( ($user->uid == 0) || ( variable_get("comment_subscribe_regged_checkbox", TRUE) ) ) {
       "comment_subscribe_regged_checkbox", TRUE) ) ) {  
143        $form['commentsubscribe'] = array(        $form['commentsubscribe'] = array(
144          '#type' => 'checkbox',        '#type' => 'checkbox',
145          '#prefix' => '<div id = "comment_suscribe">',        '#prefix' => '<div id = "comment_suscribe">',
146        '#suffix' => '</div>',        '#suffix' => '</div>',
147          '#title' => t('Email me about replies to this comment.'),        '#title' => t('Email me about replies to this comment.'),
148           '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get        '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get
149          ("comment_subscribe_default_anon_mailalert", TRUE)        ("comment_subscribe_default_comment_mailalert", TRUE)
150        );        );
151      }      }
152      else {      else {
153        $form['commentsubscribe'] = array(        $form['commentsubscribe'] = array(
154        '#type' => 'hidden',        '#type' => 'hidden',
155        '#title' => t('Mail me updates to this comment.'),        '#title' => t('Mail me updates to this comment.'),
156        '#default_value' =>$user->comment_subscribe_mailalert        '#default_value' => $user->comment_subscribe_mailalert
157        );        );
158      }      }
159      if ( $form['cid']['#value'] != '' )  {      if ( $form['cid']['#value'] != '' )  {
160          //Get the subscribe status of current comment from z_commentsubscribe table        //Get the subscribe status of current comment from z_commentsubscribe table
161          $subsrberslt = db_fetch_object(db_query("SELECT subscribe,subscribenode FROM        $subsrberslt = db_fetch_object(db_query("SELECT subscribe,subscribenode FROM
162          {z_commentsubscribe}        {z_commentsubscribe} WHERE cid = %d", arg(2)));
163          WHERE cid = %d", arg(2)));        $subscribestatus = $subsrberslt->subscribe;
164          $subscribestatus = $subsrberslt->subscribe;        $subscribenodestatus = $subsrberslt->subscribenode;
165          $subscribenodestatus = $subsrberslt->subscribenode;        $form['commentsubscribe']['#default_value'] =  $subscribestatus;
166          $form['commentsubscribe']['#default_value'] =  $subscribestatus;        $form['commentsubscribenode']['#default_value'] =  $subscribenodestatus;
         $form['commentsubscribenode']['#default_value'] =  $subscribenodestatus;  
167      }      }
168    }    }
169    else if ($form['#id'] == 'node-form' ) {    else if ($form['#id'] == 'node-form' ) {
170        $subsrberslt = db_fetch_object(db_query("SELECT nodesubscribe FROM      $subsrberslt = db_fetch_object(db_query("SELECT nodesubscribe FROM {z_nodesubscribe} WHERE nid = %d", arg(1)));
171        {z_nodesubscribe} WHERE nid = %d", arg(1)));      $subscribestatus = $subsrberslt->nodesubscribe;
172        $subscribestatus = $subsrberslt->nodesubscribe;      $form['nodesubscribe'] = array(
173        $form['nodesubscribe'] = array(     '#type' => 'checkbox',
174          '#type' => 'checkbox',     '#prefix' => '<div id = "comment_suscribe">',
175          '#prefix' => '<div id = "comment_suscribe">',      '#suffix' => '</div>',
176        '#suffix' => '</div>',     '#title' => t('Email me about replies to this node.'),
177          '#title' => t('Email me about replies to this node.'),      '#default_value' => ($user->uid != 0?$subscribestatus:1)
          '#default_value' => ($user->uid != 0?$subscribestatus:1)  
178      );      );
179    }    }
180    else {    else {
# Line 200  function comment_subscribe_user($type, & Line 189  function comment_subscribe_user($type, &
189    switch ($type) {    switch ($type) {
190    
191      case 'form':      case 'form':
192        if ( $category == 'account' ) {      if ($category == 'account') {
193          $form = array();        $form = array();
194          $form['comment_subscribe_settings'] = array(        $form['comment_subscribe_settings'] = array(
195              '#type' => 'fieldset',        '#type' => 'fieldset',
196              '#title' => t('Comment follow up subscription settings'),        '#title' => t('Comment follow up subscription settings'),
197              '#weight' => 4,        '#weight' => 4,
198              '#collapsible' => TRUE        '#collapsible' => TRUE
199              );        );
200          $form['comment_subscribe_settings']['comment_subscribe_mailalert'] = array(        $form['comment_subscribe_settings']['comment_subscribe_mailalert'] = array(
201              '#type' => 'checkbox',        '#type' => 'checkbox',
202              '#title' => t('Receive comment follow-up notification e-mails'),        '#title' => t('Receive comment follow-up notification e-mails'),
203              '#default_value' => isset($edit['comment_subscribe_mailalert']) ? $edit['comment_subscribe_mailalert'] : 1,        '#default_value' => isset($edit['comment_subscribe_mailalert']) ? $edit['comment_subscribe_mailalert'] : 1,
204              '#description' => t('Check this box to receive e-mail notification for follow-up comments to comments you    posted. ')        '#description' => t('Check this box to receive e-mail notification for follow-up comments to comments you posted. ')
205              );        );
206          return $form;        return $form;
207        }      }
208        break;      break;
209    }    }
210  }  }
211  /**  /**
# Line 224  function comment_subscribe_user($type, & Line 213  function comment_subscribe_user($type, &
213   */   */
214  function comment_subscribe_comment($comment, $op) {  function comment_subscribe_comment($comment, $op) {
215    global $user;    global $user;
216    switch($op) {    switch ($op) {
217      case 'publish':      case 'publish':
218        //Converting array to object        //Converting array to object.
219        if( is_array( $comment ) ) {        if (is_array($comment)) {
   
220          $comment = (object)$comment;          $comment = (object)$comment;
221        }        }
222        _comment_subscribe_mailalert($comment);        _comment_subscribe_mailalert($comment);
223        break;      break;
224    
225      case 'update':      case 'update':
226        //If node subscription is selected        //If node subscription is selected.
227        if(variable_get("comment_subscribe_node_alert",FALSE)) {        if (variable_get("comment_subscribe_node_alert", FALSE)) {
228          $sql = "UPDATE {z_commentsubscribe} SET subscribenode =%d WHERE          $sql = "update {z_commentsubscribe} set subscribenode =%d where cid = %d";
         cid = %d";  
229          db_query($sql, $comment['commentsubscribenode'], $comment['cid']);          db_query($sql, $comment['commentsubscribenode'], $comment['cid']);
230        }        }
231        //If comment reply subscription is selected        //If comment reply subscription is selected
232        else {        else {
233          $sql = "UPDATE {z_commentsubscribe} SET subscribe = %d UPDATE          $sql = "update {z_commentsubscribe} set subscribe = %d where cid = %d";
         cid = %d";  
234          db_query($sql, $comment['commentsubscribe'], $comment['cid']);          db_query($sql, $comment['commentsubscribe'], $comment['cid']);
235        }        }
236        break;      break;
237    
238      case 'insert':      case 'insert':
239      case 'Save':      case 'Save':
240        //Get pid from comment for current cid ,get the parents for        //Get pid from comment for current cid ,get the parents for this cid
       //this cid  
241        $notifyval = 0;        $notifyval = 0;
242         $parentrslt = db_fetch_object(db_query("SELECT pid FROM        $parentrslt = db_fetch_object(db_query("SELECT pid FROM {comments} WHERE cid = %d", $comment['cid']));
243        {comments}        $strparents = $parentrslt->pid .',';
244        WHERE cid = %d", $comment['cid']));        $prvparnt = db_fetch_object(db_query("SELECT parents FROM {z_commentsubscribe} WHERE cid = %d"
245        $strparents = $parentrslt->pid.',';  , $parentrslt->pid));
246        $prvparnt = db_fetch_object(db_query("SELECT parents FROM        $parents = $prvparnt->parents . $strparents;
247        {z_commentsubscribe}        //Checking which option is selected ie checking whether node reply or comment reply is chosen.
       WHERE cid = %d", $parentrslt->pid));  
       $parents = $prvparnt->parents.$strparents;  
       //Checking which option is selected ie checking  
       //whether node reply or comment reply is chosen.  
248        //According to the selection flag subscription is saved.        //According to the selection flag subscription is saved.
249        if(variable_get("comment_subscribe_node_alert",FALSE)) {        if (variable_get("comment_subscribe_node_alert", FALSE)) {
250          $sql = "INSERT INTO {z_commentsubscribe} (cid, parents, subscribenode)          $sql = "insert into {z_commentsubscribe} (cid, parents, subscribenode) values(%d, '%s', %d)";
         VALUES(%d, '%s', %d)";  
251          db_query($sql, $comment['cid'], $parents, $comment['commentsubscribenode']);          db_query($sql, $comment['cid'], $parents, $comment['commentsubscribenode']);
252        }        }
253        else  {        else  {
254          $sql = "INSERT INTO {z_commentsubscribe} (cid,parents,subscribe)  VALUES(%d, '%s', %d)";          $sql = "insert into {z_commentsubscribe} (cid,parents,subscribe) values(%d, '%s', %d)";
255          db_query($sql, $comment['cid'], $parents, $comment['commentsubscribe']);          db_query($sql, $comment['cid'], $parents, $comment['commentsubscribe']);
256        }        }
        break;  
     case 'delete':  
       $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d OR INSTR(parents, '%s,') ";  
       db_query($sql, $comment->cid,$comment->cid);  
257        break;        break;
258    
259        case 'delete':
260          $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d or instr(parents, '%s,') ";
261          db_query($sql, $comment->cid, $comment->cid);
262        break;
263    
264    }    }
265  }  }
266  /**  /**
# Line 285  function comment_subscribe_comment($comm Line 269  function comment_subscribe_comment($comm
269  function comment_subscribe_mail($key, &$message, $params) {  function comment_subscribe_mail($key, &$message, $params) {
270    switch ($key) {    switch ($key) {
271      case 'mail_author':      case 'mail_author':
272        $message['subject'] = $params['subject'];      $message['subject'] = $params['subject'];
273        $message['body'] = $params['body'];      $message['body'] = $params['body'];
274        break;      break;
275      case 'mail_user':      case 'mail_user':
276        $message['subject'] = $params['subject'];      $message['subject'] = $params['subject'];
277        $message['body'] = $params['body'];      $message['body'] = $params['body'];
278        break;      break;
279    }    }
280  }  }
281    
282  /**  /**
283   *Function to send mail to subscribed users if any comment is submitted   * Function to send mail to subscribed users if any comment is submitted.
284   */   */
285  function _comment_subscribe_mailalert( $comment) {  function _comment_subscribe_mailalert( $comment) {
286    global $base_url;    global $base_url;
# Line 305  function _comment_subscribe_mailalert( $ Line 289  function _comment_subscribe_mailalert( $
289    $commname= $comment->name;    $commname= $comment->name;
290    $commtext= $comment->comment;    $commtext= $comment->comment;
291    $commsubj= $comment->subject;    $commsubj= $comment->subject;
292    //Get the parents and mailid of a particular comment  
293    $parentrslt = db_fetch_object(db_query("SELECT parents,    //Get the parents and mailid of a particular comment.
294    IF(length(c.mail)<1, IFNULL(u.mail,u.init),    $parentrslt = db_fetch_object(db_query("SELECT parents, IF(length(c.mail)<1, ifnull(u.mail, u.init), c.mail) mail FROM {z_commentsubscribe} zc LEFT JOIN {comments} c on zc.cid = c.cid LEFT JOIN {users} u on u.uid = c.uid WHERE zc.cid = %d", $cid));
295    c.mail) mail FROM {z_commentsubscribe} zc    if ($parentrslt->parents != NULL) {
296    LEFT JOIN {comments} c ON zc.cid = c.cid      $arrparents =explode(',', $parentrslt->parents);
   LEFT JOIN {users} u ON u.uid = c.uid  
   WHERE zc.cid = %d", $cid));  
   if($parentrslt->parents != NULL) {  
     $arrparents =explode(',',$parentrslt->parents);  
297      $parents .= $arrparents[0];      $parents .= $arrparents[0];
298      for($i = 1; $i< count($arrparents)-1 ; $i++) {      for ($i = 1; $i < count($arrparents)-1 ; $i++) {
299        $parents .=',';        $parents .= ',';
300        $parents .= $arrparents[$i];        $parents .= $arrparents[$i];
301      }      }
302      $currmailid = $parentrslt->mail;      $currmailid = $parentrslt->mail;
303      $node = node_load($nid);      $node = node_load($nid);
304      $from = variable_get('site_mail', ini_get('sendmail_from'));      $from = variable_get('site_mail', ini_get('sendmail_from'));
305      //Get the mailid of users who subscribed for the comment replies      //Get the mailid of users who subscribed for the comment replies or node comments.
     //or node comments.  
306      if ( $GLOBALS['db_type']=='pgsql') {      if ( $GLOBALS['db_type']=='pgsql') {
307        $result = db_query(      $result = db_query(
308               "SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, ".        "SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, ".
309               "  (case when length(c.mail)<1 then coalesce (u.mail,u.init) else c.mail end) AS mail ".        "  (case when length(c.mail)<1 then coalesce (u.mail,u.init) else c.mail end) AS mail ".
310               " FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid ".        " FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid ".
311               " LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid ".        " LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid ".
312               " WHERE nid=%d  AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 ) AND c.status=0 ".        " WHERE nid=%d  AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 ) AND c.status=0 ".
313               "  AND LENGTH(case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end)>1 ".        "  AND LENGTH(case when LENGTH(c.mail)<1 then coalesce(u.mail, u.init) else c.mail end)>1 ".
314               "  AND (case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end) like '%@%.%' ".        "  AND (case when LENGTH(c.mail)<1 then coalesce(u.mail, u.init) else c.mail end) like '%@%.%' ".
315               "  AND (case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end) <> '%s' ".        "  AND (case when LENGTH(c.mail)<1 then coalesce(u.mail, u.init) else c.mail end) <> '%s' ".
316               " GROUP BY 1,2,3,4,5,6  ORDER BY mail DESC",        " GROUP BY 1,2,3,4,5,6  ORDER BY mail DESC", $nid, $parents, $currmailid);
         $nid, $parents, $currmailid  
            );  
317      }      }
318      else  {      else  {
319        $result = db_query('SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid,      $result = db_query(
320          IF(length(c.mail)<1, ifNULL(u.mail,u.init), c.mail) mail        'SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, '.
321          FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid        'IF(length(c.mail)<1, ifNULL(u.mail,u.init), c.mail) mail '.
322          LEFT JOIN {z_commentsubscribe} zc ON zc.cid=c.cid        'FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid '.
323          WHERE nid=%d  AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 )AND c.status=0        'LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid '.
324          AND LENGTH(IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail))>1        'WHERE nid=%d  AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 )AND c.status=0 '.
325          AND IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) like        'AND LENGTH(IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail))>1 '.
326          \'%@%.%\'        'AND IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) like   \'%@%.%\' '.
327          AND IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) <> \'%s\'        'AND IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) <> \'%s\' '.
328          GROUP BY IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) ORDER        'GROUP BY IF(LENGTH(c.mail)<1, ifNULL(u.mail,u.init),c.mail) ORDER '.
329          BY mail DESC',        'BY mail DESC', $nid, $parents, $currmailid);
         $nid, $parents, $currmailid  
       );  
330      }      }
331      $count=0;      $count=0;
332      while ($alert = db_fetch_object($result)) {      while ($alert = db_fetch_object($result)) {
333        $mailid = $alert->mail;        $mailid = $alert->mail;
334        $subject = t('!site :: new comment for your post.', array(        $subject = t('!site :: new comment for your post.', array(
335        '!site' => variable_get('site_name', 'drupal')));        '!site' => variable_get('site_name', 'drupal')));
336        $message = t((variable_get('comment_subscribe_default_mailtext',        $message = t((variable_get('comment_subscribe_default_mailtext', DEFAULT_MAILTEXT)),
       DEFAULT_MAILTEXT)),  
337        array(        array(
338          '!commname' => $commname,        '!commname' => $commname,
339          '!commtext' => $commtext,        '!commtext' => $commtext,
340          '!commsubj' => $commsubj,        '!commsubj' => $commsubj,
341          '!comment_url' => url('node/'.$nid,array('absolute' => TRUE))."#comment-".        '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $cid,
342          $cid,        '!node_title' =>  $node->title,
343          '!node_title' =>  $node->title,        '!node_teaser' => $node->teaser,
344          '!node_teaser' => $node->teaser,        '!mission' => variable_get('site_mission', ''),
345          '!mission' => variable_get('site_mission', ''),        '!node_body' =>  $node->body,
346          '!node_body' =>  $node->body,        '!name' => $alert->name,
347          '!name' => $alert->name,        '!site' => variable_get('site_name', 'drupal'),
348          '!site' => variable_get('site_name', 'drupal'),        '!uri' => $base_url,
349          '!uri' => $base_url,        '!uri_brief' => substr($base_url, strlen('http://')),
350          '!uri_brief' => substr($base_url, strlen('http://')),        '!date' => format_date(time()),
351          '!date' => format_date(time()),        '!login_uri' => url('user', array('absolute' => TRUE)),
352          '!login_uri' => url('user', array('absolute' => TRUE)),        '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)
353          '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)        ),
354            ),        '!link1' => url('comment_subscribe/disable/nodepost/'. $nid .'/'.
355          '!link1' => url('comment_subscribe/disable/nodepost/'.$nid.'/'.        md5($mailid), array('absolute' => TRUE)),
356          md5($mailid), array('absolute' => TRUE)),        '!link2' => url('comment_subscribe/disable/postrply/'. $alert->
357          '!link2' => url('comment_subscribe/disable/postrply/'.$alert->        cid .'/'. md5($mailid), array('absolute' => TRUE)),
358          cid.'/'.md5($mailid), array('absolute' => TRUE)),        ));
         )  
       );  
359        $_SESSION['subject'] = $subject;        $_SESSION['subject'] = $subject;
360        $_SESSION['message'] = $message;        $_SESSION['message'] = $message;
361          drupal_mail( "comment_subscribe",        drupal_mail("comment_subscribe", 'mail_user', $alert->mail, language_default(), array('body' => $message, 'subject' => $subject, 'header' => $header));
                      'mail_user',  
                      $alert->mail,  
                      language_default(),  
                      array ( 'body' => $message,  
                              'subject' => $subject,  
                              'header' => $header,  
                            ));  
   
362        $count++;        $count++;
363        if (($alert->uid)!=0)        if (($alert->uid)!=0)
364          $mylink =l( $mailid , 'user/'. $alert->uid .'/edit') ;          $mylink = l( $mailid , 'user/'. $alert->uid .'/edit') ;
365        else        else
366          $mylink =$mailid;          $mylink = $mailid;
367        // Add an entry to the watchdog log.        // Add an entry to the watchdog log.
368        watchdog('comment_subscribe', 'Subscribe !link', array('!link' => $mylink),        watchdog('comment_subscribe', 'Subscribe !link', array('!link' => $mylink),
369                  WATCHDOG_NOTICE, l(t('source comment'), 'node/'. $nid, array('fragment' => 'comment-'. $alert->cid)));        WATCHDOG_NOTICE, l(t('source comment'), 'node/'. $nid, array('fragment' => 'comment-'. $alert->cid)));
370        // revert to previous (site default) locale        // revert to previous (site default) locale.
371        $locale = $initial_locale;        $locale = $initial_locale;
372      }      }
373      //Sending mail to author of the post, if he subscribed comments to the node      // Sending mail to author of the post, if he subscribed comments to the node.
374      if ( $GLOBALS['db_type']=='pgsql') {      if ( $GLOBALS['db_type']=='pgsql') {
375        $authorid = db_result(db_query("SELECT  coalesce ( u.mail, u.init )        $authorid = db_result(db_query("SELECT  coalesce ( u.mail, u.init ) mail FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid LEFT JOIN {z_nodesubscribe} z ON z.nid = n.nid WHERE n.nid = %d AND z.nodesubscribe=1 AND mail <> '%s' ", $nid, $currmailid));
       mail FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid  
       LEFT JOIN {z_nodesubscribe} z ON z.nid = n.nid  
       WHERE n.nid = %d AND z.nodesubscribe=1 AND mail <> '%s' ", $nid, $currmailid));  
376      }      }
377      else {      else {
378        $authorid = db_result(db_query("SELECT  ifNULL(u.mail,u.init)        $authorid = db_result(db_query("SELECT  ifNULL(u.mail,u.init) mail FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid LEFT JOIN {z_nodesubscribe} z ON z.nid = n.nid WHERE n.nid = %d AND z.nodesubscribe=1 AND mail <> '%s'", $nid, $currmailid));
       mail FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid  
       LEFT JOIN {z_nodesubscribe} z ON z.nid = n.nid  
       WHERE n.nid = %d AND z.nodesubscribe=1 AND mail <> '%s'", $nid, $currmailid));  
379      }      }
380      $subject = t('!site :: new comment for your post.', array(      $subject = t('!site :: new comment for your post.', array(
381          '!site' => variable_get('site_name', 'drupal')));        '!site' => variable_get('site_name', 'drupal')));
382      $message = t((variable_get('comment_subscribe_default_author_mailtext',        $message = t((variable_get('comment_subscribe_default_author_mailtext', DEFAULT_AUTHOR_MAILTEXT)),
       DEFAULT_AUTHOR_MAILTEXT)),  
383        array(        array(
384          '!commname' => $commname,          '!commname' => $commname,
385        '!comment_url' => url('node/'.$nid,array('absolute' => TRUE))."#comment-".          '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $cid,
         $cid,  
386          '!node_title' =>  $node->title,          '!node_title' =>  $node->title,
387          '!mission' => variable_get('site_mission', ''),          '!mission' => variable_get('site_mission', ''),
388          '!name' => $alert->name,          '!name' => $alert->name,
389          '!site' => variable_get('site_name', 'drupal'),          '!site' => variable_get('site_name', 'drupal'),
390          '!uri' => $base_url,          '!uri' => $base_url,
391          '!link1' => url('comment_subscribe/disable/nodecomments/'. $nid,array('absolute' => TRUE)),          '!link1' => url('comment_subscribe/disable/nodecomments/'. $nid, array('absolute' => TRUE)),
392          )        )
393        );      );
394      $headers = array();      $headers = array();
395      drupal_mail( "comment_subscribe", 'mail_author', $authorid, language_default(), array ( 'body' => $message,      if ($authorid) {
396                               'subject' => $subject,        drupal_mail("comment_subscribe", 'mail_author', $authorid, language_default(), array('body' => $message, 'subject' => $subject, 'header' => $header ));
397                               'header' => $header,      }
                            ));  
398    
399      if( $count > 0 )      if ($count > 0)
400        drupal_set_message(t("Thanks for your comment! I just sent out %count follow-up mail notifications!", array("%count" => $count)));        drupal_set_message(t("Thanks for your comment! I just sent out %count follow-up mail notifications!", array("%count" => $count)));
401    }    }
402  }  }
# Line 454  function comment_subscribe_page() { Line 409  function comment_subscribe_page() {
409    $op = $_POST["op"];    $op = $_POST["op"];
410    $edit = $_POST["edit"];    $edit = $_POST["edit"];
411    $page_content=" ";    $page_content=" ";
412    
413    if (empty($op)) {    if (empty($op)) {
414      $op = arg(1);      $op = arg(1);
415    }    }
416    $arg = arg(3);    $arg = arg(3);
417    switch ($op) {    switch ($op) {
418      case 'disable':      case 'disable':
419        //Disable followup comments for a particular node by author      // Disable followup comments for a particular node by author.
420        $type = arg(2);      $type = arg(2);
421        $key=$arg;      $key = $arg;
422        if ( strcmp($type, 'nodecomments') == 0 ) {      if (strcmp($type, 'nodecomments') == 0) {
423          db_query("UPDATE {z_nodesubscribe} z      db_query("UPDATE {z_nodesubscribe} z SET z.nodesubscribe = 0 WHERE z.nid = %d ", $arg);
424            SET z.nodesubscribe = 0      drupal_set_message(t("Your comment follow up subscription for this node was disabled. Thanks"));
425            WHERE z.nid = %d ", $arg);      $title = t('Disabled comment follow up subscription feature for this node');
426          drupal_set_message(t("Your comment follow up subscription for      }
427          this node was disabled. Thanks"));      // Disable followup comments for a particular node.
428          $title = t('Disabled comment follow up subscription feature      else if (strcmp($type, 'nodepost') == 0) {
429          for this node');        if ($GLOBALS['db_type']=='pgsql') {
430        }          db_query("UPDATE {z_commentsubscribe} cs set subscribe=0 , subscribenode = 0 WHERE cs.cid in (SELECT c.cid from {comments} c inner join {users} u on c.uid=u.uid and c.nid= %d AND md5(case when length(c.mail)<1 then u.mail else c.mail end) = '%s')", $arg, arg(4));
       //Disable followup comments for a particular node  
       else if ( strcmp($type, 'nodepost') == 0 ) {  
         if ( $GLOBALS['db_type']=='pgsql') {  
           db_query("  
           UPDATE {z_commentsubscribe} cs SET subscribe=0 , subscribenode = 0  
           WHERE cs.cid IN (SELECT c.cid FROM {comments} c INNER JOIN {users} u ON c.uid=u.uid AND c.nid= %d  
           AND md5(case WHEN LENGTH(c.mail)<1 THEN u.mail ELSE c.mail end) = '%s')", $arg, arg(4));  
         }  
         else {  
           db_query("UPDATE {comments} c , {users} u ,  
           {z_commentsubscribe} cs  
           SET cs.subscribe = 0, cs.subscribenode = 0  
           WHERE c.cid=cs.cid AND c.uid = u.uid  
           AND c.nid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail,  
           c.mail ) ) = '%s'", $arg, arg(4));  
         }  
         drupal_set_message(t("Your comment follow up subscription for this node was disabled. Thanks"));  
         $title = t('Disabled comment follow up subscription feature for this node');  
431        }        }
       //Disable followup comments for a particular comment  
432        else {        else {
433          //Get the maximum cid for a particular comment of a givenid          db_query("UPDATE {comments} c , {users} u , {z_commentsubscribe} cs SET cs.subscribe = 0,  cs.subscribenode = 0 WHERE c.cid=cs.cid AND c.uid = u.uid AND c.nid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s'", $arg, arg(4));
434           if ( $GLOBALS['db_type']=='pgsql') {        }
435             $lstcid = db_fetch_object(db_query("        drupal_set_message(t("Your comment follow up subscription for this node was disabled. Thanks"));
436              SELECT MAX(zc.cid) AS maxcid FROM {z_commentsubscribe} zc        $title = t('Disabled comment follow up subscription feature for this node');
437              LEFT JOIN {comments} c ON c.cid = zc.cid      }
438              LEFT OUTER JOIN {users} u ON u.uid=c.uid      // Disable followup comments for a particular comment.
439              WHERE subscribe = 1 AND parents ~ '%s,'      else {
440              AND md5(CASE WHEN LENGTH( c.mail ) <1 THEN  u.mail ELSE c.mail END ) = '%s'", $arg, arg(4)));        // Get the maximum cid for a particular comment of a givenid.
441          }      if ($GLOBALS['db_type']=='pgsql') {
442          else {        $lstcid = db_fetch_object(db_query(" SELECT max(zc.cid) as maxcid FROM {z_commentsubscribe} zc LEFT JOIN {comments} c on c.cid = zc.cid LEFT OUTER JOIN {users} u ON u.uid=c.uid WHERE subscribe = 1 AND parents ~ '%s,' AND md5(case when LENGTH( c.mail ) <1 then  u.mail else c.mail end ) = '%s'", $arg, arg(4)));
443            //Get the maximum cid for a particular comment of a givenid      }
444            $lstcid = db_fetch_object(db_query("SELECT max(zc.cid) AS      else {
445              maxcid FROM {z_commentsubscribe} zc        // Get the maximum cid for a particular comment of a givenid.
446              LEFT JOIN {comments} c ON c.cid = zc.cid        $lstcid = db_fetch_object(db_query("SELECT max(zc.cid) as maxcid FROM {z_commentsubscribe} zc LEFT JOIN {comments} c on c.cid = zc.cid LEFT OUTER JOIN {users} u ON u.uid=c.uid WHERE subscribe = 1 AND instr(parents ,'%s') AND md5(IF(LENGTH(c.mail) < 1, u.mail, c.mail)) = '%s'", $arg, arg(4)));
             LEFT OUTER JOIN {users} u ON u.uid=c.uid  
             WHERE subscribe = 1 AND instr(parents ,'%s') AND md5(IF(  
             LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s'", $arg, arg(4)));  
447      }      }
448      if ( $lstcid->maxcid )      if ( $lstcid->maxcid )
449        $cid =  $lstcid->maxcid;        $cid =  $lstcid->maxcid;
450      else      else
451        $cid = $arg;        $cid = $arg;
452      db_query("UPDATE {comments} c , {users} u , {z_commentsubscribe} cs SET cs.subscribe = 0,  cs.subscribenode = 0  WHERE c.cid=cs.cid AND u.uid=c.uid        db_query("UPDATE {comments} c , {users} u , {z_commentsubscribe} cs SET cs.subscribe = 0, s.subscribenode = 0  WHERE c.cid=cs.cid AND u.uid=c.uid AND  c.cid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s' ", $cid, arg(4));
453        AND  c.cid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s' ", $cid, arg(4));        drupal_set_message(t("Your comment follow up subscription for this post was disabled. Thanks"));
454      drupal_set_message(t("Your comment follow up subscription for this post was disabled. Thanks"));        $title = t('Disabled comment follow up subscription feature  for this comment');
455      $title = t('Disabled comment follow up subscription feature  for this comment');      }
       }  
456      break;      break;
457    
458      default;      default;
459        $title = t('Comment Subscribe');        $title = t('Comment Subscribe');
460        break;      break;
461    
462    }    }
463    drupal_set_title($title);    drupal_set_title($title);
464    drupal_set_breadcrumb($breadcrumb);    drupal_set_breadcrumb($breadcrumb);
# Line 533  function comment_subscribe_page() { Line 468  function comment_subscribe_page() {
468   * Function hook_enable   * Function hook_enable
469   */   */
470  function comment_subscribe_enable() {  function comment_subscribe_enable() {
471      $num_rows_result = db_fetch_object(db_query("SELECT count(*) AS num FROM {comments} c"));
472    $num_rows_result = db_fetch_object(db_query("SELECT COUNT(*) AS num FROM {comments} c"));    if ($num_rows_result-> num != 0) {
473        // If comment_subscribe module is enabled in a live site.
474    if (  $num_rows_result-> num != 0 ) {      // For previous comments an entry in z_commentsubscribe is
475      //If comment_subscribe module is enabled in a live site.      // generated using the below code.
     //For previous comments an entry in z_commentsubscribe is  
     //generated using the below code.  
476      $level = 1;      $level = 1;
477      $ifcondition = "IF (c". $level .".pid <> 0, CONCAT(c". $level .".pid, ','),'')";      $ifcondition = "if(c". $level .".pid <> 0, concat(c". $level .".pid, ','),'')";
478      $table = "c". $level;      $table = "c". $level;
479      $join =NULL;      $join =NULL;
480    
481      //First find the level of comments      // First find the level of comments.
482      do {      do {
483          if ($level != 1) {
484       if ($level != 1) {          $prvlevel = $level - 1;
485         $prvlevel = $level - 1;          $join .= " JOIN {comments} c". $level ." on c". $prvlevel .".pid=c". $level .".cid";
486         $join .= " JOIN {comments} c". $level ." ON c". $prvlevel .".pid=c". $level .".cid";        }
487       }        $sql = "SELECT c1.cid, concat('0,', ". $ifcondition ." ) AS parents FROM {comments} c1  ". $join;
488       $sql = "SELECT c1.cid, concat('0,', ". $ifcondition ." ) AS parents FROM {comments} c1  ". $join;        $result = db_fetch_array(db_query($sql));
489       $result = db_fetch_array(db_query($sql));        if ($result != NULL) {
490       if ( $result != NULL ) {          $origsql = $sql;
491         $origsql = $sql;          $origjoin = $join;
492         $origjoin = $join;          $origifcond = $ifcondition;
493         $origifcond = $ifcondition;        }
494       }        $level++;
495       $level++;        $table = "c" . $level;
496       $table = "c" . $level;        $ifcondition = " if(c". $level ." .pid <> 0, concat(c". $level ." . pid, ','),''),". $ifcondition;
497       $ifcondition = " IF(c". $level ." .pid <> 0, CONCAT(c". $level ." . pid, ','),''),". $ifcondition;      }while ($result != NULL);
498      }while ( $result != NULL );  
499      $sql = str_replace('JOIN', 'LEFT JOIN', $origsql);      $sql = str_replace('join', 'left join', $origsql);
500      $sql = str_replace('AS parents', 'AS parents, 0 AS subscribe, 0 AS subscribenode', $sql);      $sql = str_replace('AS parents', 'AS parents, 0 as subscribe, 0 as subscribenode', $sql);
501      $sql = "INSERT INTO {z_commentsubscribe} (cid, parents, subscribe, subscribenode) ". $sql ."      $sql = "INSERT INTO {z_commentsubscribe} (cid, parents, subscribe, subscribenode) ". $sql ."
502      LEFT JOIN {z_commentsubscribe} cs ON c1.cid = cs.cid WHERE cs.subscribe IS NULL";      left join {z_commentsubscribe} cs on c1.cid = cs.cid where cs.subscribe is NULL";
503      db_query($sql);      db_query($sql);
504      //Insert previous node informations in to the z_nodesubscribe table.      // Insert previous node informations into the z_nodesubscribe table.
505      db_query("INSERT INTO {z_nodesubscribe} (nid, uid) SELECT nid,uid FROM node");      db_query("INSERT INTO {z_nodesubscribe} (nid, uid) SELECT nid,uid FROM node");
506    }    }
507   }   }

Legend:
Removed from v.1.2.2.5  
changed lines
  Added in v.1.2.2.6

  ViewVC Help
Powered by ViewVC 1.1.2