summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-09-21 11:53:17 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-09-21 11:53:17 +0200
commit2ed38036a53a489d2fcadc46ce601f8c876fca31 (patch)
treee8f36697d9300a874957b6a72c821f36b25f4c85 /inc
parentf036cff4fde59f0265f6123f6faf92cb8ba8bb26 (diff)
downloadrpg-2ed38036a53a489d2fcadc46ce601f8c876fca31.tar.gz
rpg-2ed38036a53a489d2fcadc46ce601f8c876fca31.tar.bz2
consolidate more notification code in subscription class
This is untested and probably broken currently
Diffstat (limited to 'inc')
-rw-r--r--inc/auth.php11
-rw-r--r--inc/common.php45
-rw-r--r--inc/subscription.php159
3 files changed, 126 insertions, 89 deletions
diff --git a/inc/auth.php b/inc/auth.php
index cedfdee36..3fb937613 100644
--- a/inc/auth.php
+++ b/inc/auth.php
@@ -778,23 +778,18 @@ function register() {
return false;
}
- // create substitutions for use in notification email
- $substitutions = array(
- 'NEWUSER' => $_POST['login'],
- 'NEWNAME' => $_POST['fullname'],
- 'NEWEMAIL' => $_POST['email'],
- );
+ $subscription = new Subscription();
if(!$conf['autopasswd']) {
msg($lang['regsuccess2'], 1);
- notify('', 'register', '', $_POST['login'], false, $substitutions);
+ $subscription->send_register($_POST['login'], $_POST['fullname'], $_POST['email']);
return true;
}
// autogenerated password? then send him the password
if(auth_sendPassword($_POST['login'], $pass)) {
msg($lang['regsuccess'], 1);
- notify('', 'register', '', $_POST['login'], false, $substitutions);
+ $subscription->send_register($_POST['login'], $_POST['fullname'], $_POST['email']);
return true;
} else {
msg($lang['regmailfail'], -1);
diff --git a/inc/common.php b/inc/common.php
index b4a57b154..d17061a1b 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1113,9 +1113,8 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace =
// decide if there is something to do, eg. whom to mail
if($who == 'admin') {
if(empty($conf['notify'])) return false; //notify enabled?
- $text = rawLocale('mailtext');
- $to = $conf['notify'];
- $bcc = '';
+ $tpl = 'mailtext';
+ $to = $conf['notify'];
} elseif($who == 'subscribers') {
if(!actionOK('subscribe')) return false; //subscribers enabled?
if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return false; //skip minors
@@ -1124,57 +1123,29 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace =
'COMMON_NOTIFY_ADDRESSLIST', $data,
array(new Subscription(), 'notifyaddresses')
);
- $bcc = $data['addresslist'];
- if(empty($bcc)) return false;
- $to = '';
- $text = rawLocale('subscr_single');
+ $to = $data['addresslist'];
+ if(empty($to)) return false;
+ $tpl = 'subscr_single';
} elseif($who == 'register') {
if(empty($conf['registernotify'])) return false;
$text = rawLocale('registermail');
$to = $conf['registernotify'];
- $bcc = '';
} else {
return false; //just to be safe
}
- // prepare replacements (keys not set in hrep will be taken from trep)
- $trep = array(
- 'NEWPAGE' => wl($id, '', true, '&'),
- 'PAGE' => $id,
- 'SUMMARY' => $summary
- );
- $trep = array_merge($trep, $replace);
- $hrep = array();
-
// prepare content
if($who == 'register') {
$subject = $lang['mail_new_user'].' '.$summary;
- } elseif($rev) {
- $subject = $lang['mail_changed'].' '.$id;
- $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&');
- $df = new Diff(explode("\n", rawWiki($id, $rev)),
- explode("\n", rawWiki($id)));
- $dformat = new UnifiedDiffFormatter();
- $tdiff = $dformat->format($df);
-
- $DIFF_INLINESTYLES = true;
- $dformat = new InlineDiffFormatter();
- $hdiff = $dformat->format($df);
- $hdiff = '<table>'.$hdiff.'</table>';
- $DIFF_INLINESTYLES = false;
} else {
- $subject = $lang['mail_newpage'].' '.$id;
- $trep['OLDPAGE'] = '---';
- $tdiff = rawWiki($id);
- $hdiff = nl2br(hsc($tdiff));
+ $subscription = new Subscription();
+ return $subscription->send_diff($to, $tpl, $id, $rev, $summary);
}
- $trep['DIFF'] = $tdiff;
- $hrep['DIFF'] = $hdiff;
+
// send mail
$mail = new Mailer();
$mail->to($to);
- $mail->bcc($bcc);
$mail->subject($subject);
$mail->setBody($text, $trep, $hrep);
if($who == 'subscribers') {
diff --git a/inc/subscription.php b/inc/subscription.php
index 74f4e4d03..4757b216c 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -378,15 +378,89 @@ class Subscription {
}
/**
+ * Send the diff for some page change
+ *
+ * @param string $subscriber_mail The target mail address
+ * @param string $template Mail template, should be 'subscr_digest' or 'subscr_single'
+ * @param string $id Page for which the notification is
+ * @param int|null $rev Old revision if any
+ * @param string $summary Change summary if any
+ * @return bool true if successfully sent
+ */
+ public function send_diff($subscriber_mail, $template, $id, $rev = null, $summary = '') {
+ global $DIFF_INLINESTYLES;
+
+ // prepare replacements (keys not set in hrep will be taken from trep)
+ $trep = array(
+ 'PAGE' => $id,
+ 'NEWPAGE' => wl($id, '', true, '&'),
+ 'SUMMARY' => $summary,
+ 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&')
+ );
+ $hrep = array();
+
+ if($rev) {
+ $subject = 'changed';
+ $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&');
+ $df = new Diff(explode("\n", rawWiki($id, $rev)),
+ explode("\n", rawWiki($id)));
+ $dformat = new UnifiedDiffFormatter();
+ $tdiff = $dformat->format($df);
+
+ $DIFF_INLINESTYLES = true;
+ $dformat = new InlineDiffFormatter();
+ $hdiff = $dformat->format($df);
+ $hdiff = '<table>'.$hdiff.'</table>';
+ $DIFF_INLINESTYLES = false;
+
+ } else {
+ $subject = 'newpage';
+ $trep['OLDPAGE'] = '---';
+ $tdiff = rawWiki($id);
+ $hdiff = nl2br(hsc($tdiff));
+ }
+
+ $trep['DIFF'] = $tdiff;
+ $hrep['DIFF'] = $hdiff;
+
+ return $this->send(
+ $subscriber_mail, $subject, $id,
+ $template, $trep, $hrep
+ );
+ }
+
+ public function send_register($login, $fullname, $email) {
+ global $conf;
+ global $ID;
+ if(empty($conf['registernotify'])) return false;
+
+ $trep = array(
+ 'NEWUSER' => $login,
+ 'NEWNAME' => $fullname,
+ 'NEWEMAIL' => $email,
+ );
+
+ return $this->send(
+ $conf['registernotify'],
+ 'new_user',
+ $ID,
+ 'registermail',
+ $trep
+ );
+ }
+
+ /**
* Send a digest mail
*
- * Sends a digest mail showing a bunch of changes.
+ * Sends a digest mail showing a bunch of changes of a single page. Basically the same as send_diff()
+ * but determines the last known revision first
*
* @author Adrian Lang <lang@cosmocode.de>
*
* @param string $subscriber_mail The target mail address
* @param array $id The ID
* @param int $lastupdate Time of the last notification
+ * @return bool
*/
protected function send_digest($subscriber_mail, $id, $lastupdate) {
$n = 0;
@@ -395,25 +469,10 @@ class Subscription {
$rev = (count($rev) > 0) ? $rev[0] : null;
} while(!is_null($rev) && $rev > $lastupdate);
- $replaces = array(
- 'NEWPAGE' => wl($id, '', true, '&'),
- 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&')
- );
- if(!is_null($rev)) {
- $subject = 'changed';
- $replaces['OLDPAGE'] = wl($id, "rev=$rev", true, '&');
- $df = new Diff(explode("\n", rawWiki($id, $rev)),
- explode("\n", rawWiki($id)));
- $dformat = new UnifiedDiffFormatter();
- $replaces['DIFF'] = $dformat->format($df);
- } else {
- $subject = 'newpage';
- $replaces['OLDPAGE'] = 'none';
- $replaces['DIFF'] = rawWiki($id);
- }
- $this->send(
- $subscriber_mail, $replaces, $subject, $id,
- 'subscr_digest'
+ return $this->send_diff(
+ $subscriber_mail,
+ 'subscr_digest',
+ $id, $rev
);
}
@@ -427,27 +486,35 @@ class Subscription {
* @param string $subscriber_mail The target mail address
* @param array $ids Array of ids
* @param string $ns_id The id of the namespace
+ * @return bool
*/
protected function send_list($subscriber_mail, $ids, $ns_id) {
if(count($ids) === 0) return;
- global $conf;
- $list = '';
+
+ $tlist = '';
+ $hlist = '<ul>';
foreach($ids as $id) {
- $list .= '* '.wl($id, array(), true).NL;
+ $link = wl($id, array(), true);
+ $tlist .= '* '.$link.NL;
+ $hlist .= '<li><a href="'.$link.'">'.hsc($id).'</a></li>'.NL;
}
- $this->send(
+ $hlist = '</ul>';
+
+ $id = prettyprint_id($ns_id);
+ $trep = array(
+ 'DIFF' => rtrim($tlist),
+ 'PAGE' => $id,
+ 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&')
+ );
+ $hrep = array(
+ 'DIFF' => $hlist
+ );
+
+ return $this->send(
$subscriber_mail,
- array(
- 'DIFF' => rtrim($list),
- 'SUBSCRIBE' => wl(
- $ns_id.$conf['start'],
- array('do' => 'subscribe'),
- true, '&'
- )
- ),
'subscribe_list',
- prettyprint_id($ns_id),
- 'subscr_list'
+
+ 'subscr_list', $trep, $hrep
);
}
@@ -457,30 +524,34 @@ class Subscription {
* @author Adrian Lang <lang@cosmocode.de>
*
* @param string $subscriber_mail The target mail address
- * @param array $replaces Predefined parameters used to parse the
- * template
* @param string $subject The lang id of the mail subject (without the
* prefix “mail_”)
* @param string $id The page or namespace id
* @param string $template The name of the mail template
+ * @param array $trep Predefined parameters used to parse the
+ * template (in text format)
+ * @param array $hrep Predefined parameters used to parse the
+ * template (in HTML format), null to default to $trep
* @return bool
*/
- protected function send($subscriber_mail, $replaces, $subject, $id, $template) {
+ protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) {
global $lang;
$text = rawLocale($template);
- $trep = array_merge($replaces, array('PAGE' => $id));
+ $trep = array_merge(
+ $trep, array(
+
+ )
+ );
$subject = $lang['mail_'.$subject].' '.$id;
$mail = new Mailer();
$mail->bcc($subscriber_mail);
$mail->subject($subject);
- $mail->setBody($text, $trep);
- $mail->setHeader(
- 'List-Unsubscribe',
- '<'.wl($id, array('do'=> 'subscribe'), true, '&').'>',
- false
- );
+ $mail->setBody($text, $trep, $hrep);
+ if(isset($trep['SUBSCRIBE'])){
+ $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false);
+ }
return $mail->send();
}