/[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.6, Fri Jan 30 07:46:35 2009 UTC revision 1.2.2.7, Fri Jan 30 08:23:50 2009 UTC
# Line 18  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_urlYou can stop receiving emails when someone replies to this blog post,  !comment_urlYou 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,
25  by going to !link2  by going to !link2
26    
27  If you have an account at the site and if you have auto-blog-following enabled in your account, you will receive emails like this for all replies to a blog post you commented on. You can disable this unchecking the flag at the time you post the comment.  If you have an account at the site and if you have auto-blog-following enabled in your account, you will receive emails like this for all replies to a blog post you commented on. You can disable this unchecking the flag at the time you post the comment.
# Line 98  function comment_subscribe_perm() { Line 98  function comment_subscribe_perm() {
98  function comment_subscribe_nodeapi(&$node, $op, $teaser, $page) {  function comment_subscribe_nodeapi(&$node, $op, $teaser, $page) {
99    switch ($op) {    switch ($op) {
100      case 'insert':      case 'insert':
101        $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.
109   * set validation hook.   * set validation hook.
110   */   */
111  function comment_subscribe_form_alter(&$form, $form_state, $form_id) {  function comment_subscribe_form_alter(&$form, $form_state, $form_id) {
112    global $user;    global $user;
113    //Checking whether the form is comment_form or not.    //Checking whether the form is comment_form or not.
114    if ( ($form_id == 'comment_form')) {    if ( ($form_id == 'comment_form')) {
# Line 125  function comment_subscribe_form_alter(&$ Line 125  function comment_subscribe_form_alter(&$
125          );          );
126          $form['submitextra']['submit'] = array(          $form['submitextra']['submit'] = array(
127          '#type' => 'submit',          '#type' => 'submit',
128          '#value' => t('Save'),          '#value' => t('Save'),
129          '#weight' => -20);          '#weight' => -20);
130        }        }
131      }      }
# Line 133  function comment_subscribe_form_alter(&$ Line 133  function comment_subscribe_form_alter(&$
133        $form['commentsubscribenode'] = array(        $form['commentsubscribenode'] = array(
134        '#type' => 'checkbox',        '#type' => 'checkbox',
135        '#prefix' => '<div id = "comment_suscribe">',        '#prefix' => '<div id = "comment_suscribe">',
136        '#suffix' => '</div>',        '#suffix' => '</div>',
137        '#title' => t('Email me about all replies to this article.'),        '#title' => t('Email me about all replies to this article.'),
138        '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get        '#default_value' => ($user->uid != 0)?$user->comment_subscribe_mailalert:variable_get
139        ("comment_subscribe_default_node_mailalert", FALSE)        ("comment_subscribe_default_node_mailalert", FALSE)
140        );        );
# Line 143  function comment_subscribe_form_alter(&$ Line 143  function comment_subscribe_form_alter(&$
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_comment_mailalert", TRUE)        ("comment_subscribe_default_comment_mailalert", TRUE)
150        );        );
# Line 152  function comment_subscribe_form_alter(&$ Line 152  function comment_subscribe_form_alter(&$
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      }      }
# Line 161  function comment_subscribe_form_alter(&$ Line 161  function comment_subscribe_form_alter(&$
161        $subsrberslt = db_fetch_object(db_query("SELECT subscribe,subscribenode FROM        $subsrberslt = db_fetch_object(db_query("SELECT subscribe,subscribenode FROM
162        {z_commentsubscribe} WHERE cid = %d", arg(2)));        {z_commentsubscribe} WHERE cid = %d", arg(2)));
163        $subscribestatus = $subsrberslt->subscribe;        $subscribestatus = $subsrberslt->subscribe;
164        $subscribenodestatus = $subsrberslt->subscribenode;        $subscribenodestatus = $subsrberslt->subscribenode;
165        $form['commentsubscribe']['#default_value'] =  $subscribestatus;        $form['commentsubscribe']['#default_value'] =  $subscribestatus;
166        $form['commentsubscribenode']['#default_value'] =  $subscribenodestatus;        $form['commentsubscribenode']['#default_value'] =  $subscribenodestatus;
167      }      }
# Line 172  function comment_subscribe_form_alter(&$ Line 172  function comment_subscribe_form_alter(&$
172      $form['nodesubscribe'] = array(      $form['nodesubscribe'] = array(
173     '#type' => 'checkbox',     '#type' => 'checkbox',
174     '#prefix' => '<div id = "comment_suscribe">',     '#prefix' => '<div id = "comment_suscribe">',
175      '#suffix' => '</div>',      '#suffix' => '</div>',
176     '#title' => t('Email me about replies to this node.'),     '#title' => t('Email me about replies to this node.'),
177      '#default_value' => ($user->uid != 0?$subscribestatus:1)      '#default_value' => ($user->uid != 0?$subscribestatus:1)
178      );      );
179    }    }
# Line 208  function comment_subscribe_user($type, & Line 208  function comment_subscribe_user($type, &
208      break;      break;
209    }    }
210  }  }
211  /**  /**
212   * Implement comment hook and check the publish status   * Implement comment hook and check the publish status
213   */   */
214  function comment_subscribe_comment($comment, $op) {  function comment_subscribe_comment($comment, $op) {
# Line 225  function comment_subscribe_comment($comm Line 225  function comment_subscribe_comment($comm
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 cid = %d";          $sql = "UPDATE {z_commentsubscribe} SET subscribenode =%d WHERE 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 where cid = %d";          $sql = "UPDATE {z_commentsubscribe} SET subscribe = %d WHERE 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 this cid        //Get pid from comment for current cid ,get the parents for this cid
241        $notifyval = 0;        $notifyval = 0;
242        $parentrslt = db_fetch_object(db_query("SELECT pid FROM {comments} WHERE cid = %d", $comment['cid']));        $parentrslt = db_fetch_object(db_query("SELECT pid FROM {comments} WHERE cid = %d", $comment['cid']));
243        $strparents = $parentrslt->pid .',';        $strparents = $parentrslt->pid .',';
# Line 247  function comment_subscribe_comment($comm Line 247  function comment_subscribe_comment($comm
247        //Checking which option is selected ie checking whether node reply or comment reply is chosen.        //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) values(%d, '%s', %d)";          $sql = "INSERT INTO {z_commentsubscribe} (cid, parents, subscribenode) 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        }        }
257        break;        break;
258    
259      case 'delete':      case 'delete':
260        $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d or instr(parents, '%s,') ";        $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d or INSTR(parents, '%s,') ";
261        db_query($sql, $comment->cid, $comment->cid);        db_query($sql, $comment->cid, $comment->cid);
262      break;      break;
263    
# Line 276  function comment_subscribe_mail($key, &$ Line 276  function comment_subscribe_mail($key, &$
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  /**  /**
# Line 313  function _comment_subscribe_mailalert( $ Line 313  function _comment_subscribe_mailalert( $
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", $nid, $parents, $currmailid);        " GROUP BY 1,2,3,4,5,6  ORDER BY mail DESC", $nid, $parents, $currmailid);
317      }      }
318      else  {      else  {
319      $result = db_query(      $result = db_query(
320        'SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, '.        'SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, '.
321        'IF(length(c.mail)<1, ifNULL(u.mail,u.init), c.mail) mail '.        'IF(length(c.mail)<1, ifNULL(u.mail,u.init), c.mail) mail '.
322        '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 '.
323        'LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid '.        'LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid '.
# Line 340  function _comment_subscribe_mailalert( $ Line 340  function _comment_subscribe_mailalert( $
340        '!commsubj' => $commsubj,        '!commsubj' => $commsubj,
341        '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $cid,        '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $cid,
342        '!node_title' =>  $node->title,        '!node_title' =>  $node->title,
343        '!node_teaser' => $node->teaser,        '!node_teaser' => $node->teaser,
344        '!mission' => variable_get('site_mission', ''),        '!mission' => variable_get('site_mission', ''),
345        '!node_body' =>  $node->body,        '!node_body' =>  $node->body,
346        '!name' => $alert->name,        '!name' => $alert->name,
347        '!site' => variable_get('site_name', 'drupal'),        '!site' => variable_get('site_name', 'drupal'),
348        '!uri' => $base_url,        '!uri' => $base_url,
349        '!uri_brief' => substr($base_url, strlen('http://')),        '!uri_brief' => drupal_substr($base_url, drupal_strlen('http://')),
350        '!date' => format_date(time()),        '!date' => format_date(time()),
351        '!login_uri' => url('user', array('absolute' => TRUE)),        '!login_uri' => url('user', array('absolute' => TRUE)),
352        '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)        '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)
353        ),        ),
354        '!link1' => url('comment_subscribe/disable/nodepost/'. $nid .'/'.        '!link1' => url('comment_subscribe/disable/nodepost/'. $nid .'/'.
# Line 360  function _comment_subscribe_mailalert( $ Line 360  function _comment_subscribe_mailalert( $
360        $_SESSION['message'] = $message;        $_SESSION['message'] = $message;
361        drupal_mail("comment_subscribe", 'mail_user', $alert->mail, language_default(), array('body' => $message, 'subject' => $subject, 'header' => $header));        drupal_mail("comment_subscribe", '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;
# Line 384  function _comment_subscribe_mailalert( $ Line 384  function _comment_subscribe_mailalert( $
384          '!commname' => $commname,          '!commname' => $commname,
385          '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $cid,          '!comment_url' => url('node/'. $nid, array('absolute' => TRUE)) ."#comment-". $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      if ($authorid) {      if ($authorid) {
396        drupal_mail("comment_subscribe", 'mail_author', $authorid, language_default(), array('body' => $message, 'subject' => $subject, 'header' => $header ));        drupal_mail("comment_subscribe", 'mail_author', $authorid, language_default(), array('body' => $message, 'subject' => $subject, 'header' => $header ));
397      }      }
# Line 471  function comment_subscribe_enable() { Line 471  function comment_subscribe_enable() {
471    $num_rows_result = db_fetch_object(db_query("SELECT count(*) AS num FROM {comments} c"));    $num_rows_result = db_fetch_object(db_query("SELECT count(*) AS num FROM {comments} c"));
472    if ($num_rows_result-> num != 0) {    if ($num_rows_result-> num != 0) {
473      // If comment_subscribe module is enabled in a live site.      // If comment_subscribe module is enabled in a live site.
474      // For previous comments an entry in z_commentsubscribe is      // For previous comments an entry in z_commentsubscribe is
475      // generated using the below code.      // 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) {        if ($level != 1) {
# Line 504  function comment_subscribe_enable() { Line 504  function comment_subscribe_enable() {
504      // Insert previous node informations into 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.6  
changed lines
  Added in v.1.2.2.7

  ViewVC Help
Powered by ViewVC 1.1.2