Browse files

Added unsubscribing from comments. Closes #23.

  • Loading branch information...
1 parent 355a674 commit 2d0142df46b7f30cb50e71d29b3a752ee32aa394 @foosel foosel committed Nov 8, 2009
Showing with 40 additions and 15 deletions.
  1. +6 −2 action/comments.php
  2. +1 −1 db/latest.version
  3. +1 −0 db/update0006.sql
  4. +24 −11 helper/comments.php
  5. +1 −1 helper/sqlite.php
  6. +5 −0 lang/en/lang.php
  7. +2 −0 lang/en/subscribermail.txt
View
8 action/comments.php
@@ -32,12 +32,16 @@ function register(&$controller) {
}
function handle_act_preprocess(&$event, $param) {
- global $INFO;
+ global $INFO, $ID;
- // optin and optout
+ // optin
if($_REQUEST['btngo'])
$this->commenthelper->optin($_REQUEST['btngo']);
+ // unsubscribe
+ if ($_REQUEST['btngu'])
+ $this->commenthelper->unsubscribe_by_key(md5($ID), $_REQUEST['btngu']);
+
global $BLOGTNG;
$BLOGTNG = array();
View
2 db/latest.version
@@ -1 +1 @@
-5
+6
View
1 db/update0006.sql
@@ -0,0 +1 @@
+CREATE INDEX idx_optin_key ON optin(key);
View
35 helper/comments.php
@@ -229,24 +229,20 @@ function send_subscriber_mails($comment){
if(!$this->getConf('comments_subscription')) return;
// get subscribers
- $sql = "SELECT A.mail as mail
+ $sql = "SELECT A.mail as mail, B.key as key
FROM subscriptions A, optin B
WHERE A.mail = B.mail
AND B.optin = 1
AND A.pid = ?";
$res = $this->sqlitehelper->query($sql,$comment['pid']);
$rows = $this->sqlitehelper->res2arr($res);
- $mails = array();
foreach($rows as $row){
// ignore commenter herself:
if($row['mail'] == $comment['mail']) continue;
// ignore author herself:
- if($row['mail'] == $entry['email']) continue;
- $mails[] = $row['mail'];
+ if($row['mail'] == $entry['mail']) continue;
+ mail_send($row['mail'], $title, str_replace('@UNSUBSCRIBE@', wl($entry['page'],array('btngu'=>$row['key']),true), $stext), $conf['mailfrom']);
}
- if(!count($mails)) return;
-
- mail_send('', $title, $stext, $conf['mailfrom'], '', join(',',$mails));
}
/**
@@ -260,9 +256,6 @@ function send_optin_mail($mail,$key){
$repl = array(
'@TITLE@' => $conf['title'],
- '@NAME@' => $comment['name'],
- '@COMMENT@' => $comment['text'],
- '@USER@' => $comment['name'],
'@URL@' => wl('',array('btngo'=>$key),true),
'@DOKUWIKIURL@' => DOKU_URL,
);
@@ -308,17 +301,37 @@ function subscribe($pid, $mail, $optin=-3) {
}
+ function unsubscribe_by_key($pid, $key) {
+ $sql = 'SELECT mail FROM optin WHERE key = ?';
+ $res = $this->sqlitehelper->query($sql, $key);
+ $row = $this->sqlitehelper->res2row($res);
+ if (!$row) {
+ msg($this->getLang('unsubscribe_err_key'), -1);
+ return;
+ }
+
+ $this->unsubscribe($pid, $row['mail']);
+ }
+
/**
* Unsubscribe entry
*/
function unsubscribe($pid, $mail) {
+ $sql = 'DELETE FROM subscriptions WHERE pid = ? AND mail = ?';
+ $this->sqlitehelper->query($sql, $pid, $mail);
+ $upd = sqlite_changes($this->sqlitehelper->db);
+ if ($upd) {
+ msg($this->getLang('unsubscribe_ok'), 1);
+ } else {
+ msg($this->getlang('unsubscribe_err_other'), -1);
+ }
}
/**
* Opt in
*/
function optin($key) {
- $sql = "UPDATE optin SET optin = 1 WHERE key = ?";
+ $sql = 'UPDATE optin SET optin = 1 WHERE key = ?';
$this->sqlitehelper->query($sql,$key);
$upd = sqlite_changes($this->sqlitehelper->db);
View
2 helper/sqlite.php
@@ -195,7 +195,7 @@ function res2arr($res){
* Return the wanted row from a given result set as
* associative array
*/
- function res2row($res,$rownum){
+ function res2row($res,$rownum=0){
if(!@sqlite_seek($res,$rownum)){
return false;
}
View
5 lang/en/lang.php
@@ -43,6 +43,11 @@
$lang['optin_ok'] = 'Thank you. You\'ll now receive comment updates via mail';
$lang['optin_err'] = 'Ooops. Couldn\'t find that key. Maybe a copy\'n\'paste error?';
+
+$lang['unsubscribe_ok'] = 'Unsubscription successful. You will no longer be notified about new comments to this post.';
+$lang['unsubscribe_err_key'] = 'Ooops. Couldn\'t find that key. Maybe a copy\'n\'paste error?';
+$lang['unsubscribe_err_other'] = 'Oooops. Couldn\'t find your subscription. Maybe a copy\'n\'paste error?';
+
$lang['btn_comment_edit'] = 'Edit';
$lang['act_comment_edit'] = 'Edit Comment';
View
2 lang/en/subscribermail.txt
@@ -10,6 +10,8 @@ A new comment was added to the article
You can read reply to the comment at
@URL@
+You can unsubscribe from further notifications at
+@UNSUBSCRIBE@
--
This mail was generated by DokuWiki at

0 comments on commit 2d0142d

Please sign in to comment.