/** * Sends a notify mail on page change or registration * * @param string $id The changed page * @param string $who Who to notify (admin|subscribers|register) * @param int $rev Old page revision * @param string $summary What changed * @param boolean $minor Is this a minor edit? * @param array $replace Additional string substitutions, @KEY@ to be replaced by value * * @author Andreas Gohr <*****@*****.**> */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { global $lang; global $conf; global $INFO; // decide if there is something to do if ($who == 'admin') { if (empty($conf['notify'])) { return; } //notify enabled? $text = rawLocale('mailtext'); $to = $conf['notify']; $bcc = ''; } elseif ($who == 'subscribers') { if (!$conf['subscribers']) { return; } //subscribers enabled? if ($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) { return; } //skip minors $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; if (empty($bcc)) { return; } $to = ''; $text = rawLocale('subscr_single'); } elseif ($who == 'register') { if (empty($conf['registernotify'])) { return; } $text = rawLocale('registermail'); $to = $conf['registernotify']; $bcc = ''; } else { return; //just to be safe } $ip = clientIP(); $text = str_replace('@DATE@', dformat(), $text); $text = str_replace('@BROWSER@', $_SERVER['HTTP_USER_AGENT'], $text); $text = str_replace('@IPADDRESS@', $ip, $text); $text = str_replace('@HOSTNAME@', gethostsbyaddrs($ip), $text); $text = str_replace('@NEWPAGE@', wl($id, '', true, '&'), $text); $text = str_replace('@PAGE@', $id, $text); $text = str_replace('@TITLE@', $conf['title'], $text); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@SUMMARY@', $summary, $text); $text = str_replace('@USER@', $_SERVER['REMOTE_USER'], $text); $text = str_replace('@NAME@', $INFO['userinfo']['name'], $text); $text = str_replace('@MAIL@', $INFO['userinfo']['mail'], $text); foreach ($replace as $key => $substitution) { $text = str_replace('@' . strtoupper($key) . '@', $substitution, $text); } if ($who == 'register') { $subject = $lang['mail_new_user'] . ' ' . $summary; } elseif ($rev) { $subject = $lang['mail_changed'] . ' ' . $id; $text = str_replace('@OLDPAGE@', wl($id, "rev={$rev}", true, '&'), $text); $df = new Diff(explode("\n", rawWiki($id, $rev)), explode("\n", rawWiki($id))); $dformat = new UnifiedDiffFormatter(); $diff = $dformat->format($df); } else { $subject = $lang['mail_newpage'] . ' ' . $id; $text = str_replace('@OLDPAGE@', 'none', $text); $diff = rawWiki($id); } $text = str_replace('@DIFF@', $diff, $text); if (utf8_strlen($conf['title']) < 20) { $subject = '[' . $conf['title'] . '] ' . $subject; } else { $subject = '[' . utf8_substr($conf['title'], 0, 20) . '...] ' . $subject; } mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); }
/** * Prepare default token replacement strings * * Populates the '$replacements' property. * Should be called by the class constructor */ protected function prepareTokenReplacements() { global $INFO; global $conf; /* @var Input $INPUT */ global $INPUT; global $lang; $ip = clientIP(); $cip = gethostsbyaddrs($ip); $this->replacements['text'] = array('DATE' => dformat(), 'BROWSER' => $INPUT->server->str('HTTP_USER_AGENT'), 'IPADDRESS' => $ip, 'HOSTNAME' => $cip, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL, 'USER' => $INPUT->server->str('REMOTE_USER'), 'NAME' => $INFO['userinfo']['name'], 'MAIL' => $INFO['userinfo']['mail']); $signature = str_replace('@DOKUWIKIURL@', $this->replacements['text']['DOKUWIKIURL'], $lang['email_signature_text']); $this->replacements['text']['EMAILSIGNATURE'] = "\n-- \n" . $signature . "\n"; $this->replacements['html'] = array('DATE' => '<i>' . hsc(dformat()) . '</i>', 'BROWSER' => hsc($INPUT->server->str('HTTP_USER_AGENT')), 'IPADDRESS' => '<code>' . hsc($ip) . '</code>', 'HOSTNAME' => '<code>' . hsc($cip) . '</code>', 'TITLE' => hsc($conf['title']), 'DOKUWIKIURL' => '<a href="' . DOKU_URL . '">' . DOKU_URL . '</a>', 'USER' => hsc($INPUT->server->str('REMOTE_USER')), 'NAME' => hsc($INFO['userinfo']['name']), 'MAIL' => '<a href="mailto:"' . hsc($INFO['userinfo']['mail']) . '">' . hsc($INFO['userinfo']['mail']) . '</a>'); $signature = $lang['email_signature_text']; if (!empty($lang['email_signature_html'])) { $signature = $lang['email_signature_html']; } $signature = str_replace(array('@DOKUWIKIURL@', "\n"), array($this->replacements['html']['DOKUWIKIURL'], '<br />'), $signature); $this->replacements['html']['EMAILSIGNATURE'] = $signature; }
/** * Send a mail about the new comment * * Mails are sent to the author of the post and * all subscribers that opted-in */ function send_subscriber_mails($comment) { global $conf; // get general article info $sql = "SELECT title, page, mail\n FROM entries\n WHERE pid = ?"; $res = $this->sqlitehelper->query($sql, $comment['pid']); $entry = $this->sqlitehelper->res2row($res, 0); // prepare mail bodies $atext = io_readFile($this->localFN('notifymail')); $stext = io_readFile($this->localFN('subscribermail')); $title = sprintf($this->getLang('subscr_subject'), $entry['title']); $repl = array('@TITLE@' => $entry['title'], '@NAME@' => $comment['name'], '@COMMENT@' => $comment['text'], '@USER@' => $comment['name'], '@MAIL@' => $comment['mail'], '@DATE@' => dformat(time()), '@BROWSER@' => $_SERVER['HTTP_USER_AGENT'], '@IPADDRESS@' => clientIP(), '@HOSTNAME@' => gethostsbyaddrs(clientIP()), '@URL@' => wl($entry['page'], '', true), '@DOKUWIKIURL@' => DOKU_URL); $atext = str_replace(array_keys($repl), array_values($repl), $atext); $stext = str_replace(array_keys($repl), array_values($repl), $stext); // notify author $mails = array_map('trim', split(',', $conf['notify'])); $mails[] = $entry['mail']; $mails = array_unique(array_filter($mails)); if (count($mails) > 0) { mail_send('', $title, $atext, $conf['mailfrom'], '', implode(',', $mails)); } // finish here when subscriptions disabled if (!$this->getConf('comments_subscription')) { return; } // get subscribers $sql = "SELECT A.mail as mail, B.key as key\n FROM subscriptions A, optin B\n WHERE A.mail = B.mail\n AND B.optin = 1\n AND A.pid = ?"; $res = $this->sqlitehelper->query($sql, $comment['pid']); $rows = $this->sqlitehelper->res2arr($res); foreach ($rows as $row) { // ignore commenter herself: if ($row['mail'] == $comment['mail']) { continue; } // ignore email addresses already notified: if (in_array($row['mail'], $mails)) { continue; } mail_send($row['mail'], $title, str_replace('@UNSUBSCRIBE@', wl($entry['page'], array('btngu' => $row['key']), true), $stext), $conf['mailfrom']); } }
/** * Set the text and HTML body and apply replacements * * This function applies a whole bunch of default replacements in addition * to the ones specidifed as parameters * * If you pass the HTML part or HTML replacements yourself you have to make * sure you encode all HTML special chars correctly * * @param string $text plain text body * @param array $textrep replacements to apply on the text part * @param array $htmlrep replacements to apply on the HTML part, leave null to use $textrep * @param string $html the HTML body, leave null to create it from $text * @param bool $wrap wrap the HTML in the default header/Footer */ public function setBody($text, $textrep = null, $htmlrep = null, $html = null, $wrap = true) { global $INFO; global $conf; /* @var Input $INPUT */ global $INPUT; $htmlrep = (array) $htmlrep; $textrep = (array) $textrep; // create HTML from text if not given if (is_null($html)) { $html = $text; $html = hsc($html); $html = preg_replace('/^-----*$/m', '<hr >', $html); $html = nl2br($html); } if ($wrap) { $wrap = rawLocale('mailwrap', 'html'); $html = preg_replace('/\\n-- <br \\/>.*$/s', '', $html); //strip signature $html = str_replace('@HTMLBODY@', $html, $wrap); } // copy over all replacements missing for HTML (autolink URLs) foreach ($textrep as $key => $value) { if (isset($htmlrep[$key])) { continue; } if (media_isexternal($value)) { $htmlrep[$key] = '<a href="' . hsc($value) . '">' . hsc($value) . '</a>'; } else { $htmlrep[$key] = hsc($value); } } // embed media from templates $html = preg_replace_callback('/@MEDIA\\(([^\\)]+)\\)@/', array($this, 'autoembed_cb'), $html); // prepare default replacements $ip = clientIP(); $cip = gethostsbyaddrs($ip); $trep = array('DATE' => dformat(), 'BROWSER' => $INPUT->server->str('HTTP_USER_AGENT'), 'IPADDRESS' => $ip, 'HOSTNAME' => $cip, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL, 'USER' => $INPUT->server->str('REMOTE_USER'), 'NAME' => $INFO['userinfo']['name'], 'MAIL' => $INFO['userinfo']['mail']); $trep = array_merge($trep, (array) $textrep); $hrep = array('DATE' => '<i>' . hsc(dformat()) . '</i>', 'BROWSER' => hsc($INPUT->server->str('HTTP_USER_AGENT')), 'IPADDRESS' => '<code>' . hsc($ip) . '</code>', 'HOSTNAME' => '<code>' . hsc($cip) . '</code>', 'TITLE' => hsc($conf['title']), 'DOKUWIKIURL' => '<a href="' . DOKU_URL . '">' . DOKU_URL . '</a>', 'USER' => hsc($INPUT->server->str('REMOTE_USER')), 'NAME' => hsc($INFO['userinfo']['name']), 'MAIL' => '<a href="mailto:"' . hsc($INFO['userinfo']['mail']) . '">' . hsc($INFO['userinfo']['mail']) . '</a>'); $hrep = array_merge($hrep, (array) $htmlrep); // Apply replacements foreach ($trep as $key => $substitution) { $text = str_replace('@' . strtoupper($key) . '@', $substitution, $text); } foreach ($hrep as $key => $substitution) { $html = str_replace('@' . strtoupper($key) . '@', $substitution, $html); } $this->setHTML($html); $this->setText($text); }
/** * Send a notify mail on uploads * * @author Andreas Gohr <*****@*****.**> */ function media_notify($id, $file, $mime, $old_rev = false) { global $lang; global $conf; global $INFO; if (empty($conf['notify'])) { return; } //notify enabled? $ip = clientIP(); $text = rawLocale('uploadmail'); $text = str_replace('@DATE@', dformat(), $text); $text = str_replace('@BROWSER@', $_SERVER['HTTP_USER_AGENT'], $text); $text = str_replace('@IPADDRESS@', $ip, $text); $text = str_replace('@HOSTNAME@', gethostsbyaddrs($ip), $text); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@USER@', $_SERVER['REMOTE_USER'], $text); $text = str_replace('@MIME@', $mime, $text); $text = str_replace('@MEDIA@', ml($id, '', true, '&', true), $text); $text = str_replace('@SIZE@', filesize_h(filesize($file)), $text); if ($old_rev && $conf['mediarevisions']) { $text = str_replace('@OLD@', ml($id, "rev={$old_rev}", true, '&', true), $text); } else { $text = str_replace('@OLD@', '', $text); } if (empty($conf['mailprefix'])) { $subject = '[' . $conf['title'] . '] ' . $lang['mail_upload'] . ' ' . $id; } else { $subject = '[' . $conf['mailprefix'] . '] ' . $lang['mail_upload'] . ' ' . $id; } mail_send($conf['notify'], $subject, $text, $conf['mailfrom']); }
/** * Send a notify mail on uploads * * @author Andreas Gohr <*****@*****.**> */ function media_notify($id, $file, $mime) { global $lang; global $conf; if (empty($conf['notify'])) { return; } //notify enabled? $ip = clientIP(); $text = rawLocale('uploadmail'); $text = str_replace('@DATE@', dformat(), $text); $text = str_replace('@BROWSER@', $_SERVER['HTTP_USER_AGENT'], $text); $text = str_replace('@IPADDRESS@', $ip, $text); $text = str_replace('@HOSTNAME@', gethostsbyaddrs($ip), $text); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@USER@', $_SERVER['REMOTE_USER'], $text); $text = str_replace('@MIME@', $mime, $text); $text = str_replace('@MEDIA@', ml($id, '', true, '&', true), $text); $text = str_replace('@SIZE@', filesize_h(filesize($file)), $text); $from = $conf['mailfrom']; $from = str_replace('@USER@', $_SERVER['REMOTE_USER'], $from); $from = str_replace('@NAME@', $INFO['userinfo']['name'], $from); $from = str_replace('@MAIL@', $INFO['userinfo']['mail'], $from); $subject = '[' . $conf['title'] . '] ' . $lang['mail_upload'] . ' ' . $id; mail_send($conf['notify'], $subject, $text, $from); }
/** * Sends a notify mail on page change * * @param string $id The changed page * @param string $who Who to notify (admin|subscribers) * @param int $rev Old page revision * @param string $summary What changed * @param boolean $minor Is this a minor edit? * @param array $replace Additional string substitutions, @KEY@ to be replaced by value * * @author Andreas Gohr <*****@*****.**> */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { global $lang; global $conf; global $INFO; // decide if there is something to do if ($who == 'admin') { if (empty($conf['notify'])) { return; } //notify enabled? $text = rawLocale('mailtext'); $to = $conf['notify']; $bcc = ''; } elseif ($who == 'subscribers') { if (!$conf['subscribers']) { return; } //subscribers enabled? if ($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) { return; } //skip minors $bcc = subscriber_addresslist($id, false); if (empty($bcc)) { return; } $to = ''; $text = rawLocale('subscribermail'); } elseif ($who == 'register') { if (empty($conf['registernotify'])) { return; } $text = rawLocale('registermail'); $to = $conf['registernotify']; $bcc = ''; } else { return; //just to be safe } $ip = clientIP(); $text = str_replace('@DATE@', strftime($conf['dformat']), $text); $text = str_replace('@BROWSER@', $_SERVER['HTTP_USER_AGENT'], $text); $text = str_replace('@IPADDRESS@', $ip, $text); $text = str_replace('@HOSTNAME@', gethostsbyaddrs($ip), $text); $text = str_replace('@NEWPAGE@', wl($id, '', true, '&'), $text); $text = str_replace('@PAGE@', $id, $text); $text = str_replace('@TITLE@', $conf['title'], $text); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@SUMMARY@', $summary, $text); $text = str_replace('@USER@', $_SERVER['REMOTE_USER'], $text); foreach ($replace as $key => $substitution) { $text = str_replace('@' . strtoupper($key) . '@', $substitution, $text); } if ($who == 'register') { $subject = $lang['mail_new_user'] . ' ' . $summary; } elseif ($rev) { $subject = $lang['mail_changed'] . ' ' . $id; $text = str_replace('@OLDPAGE@', wl($id, "rev={$rev}", true, '&'), $text); require_once DOKU_INC . 'inc/DifferenceEngine.php'; $df = new Diff(split("\n", rawWiki($id, $rev)), split("\n", rawWiki($id))); $dformat = new UnifiedDiffFormatter(); $diff = $dformat->format($df); } else { $subject = $lang['mail_newpage'] . ' ' . $id; $text = str_replace('@OLDPAGE@', 'none', $text); $diff = rawWiki($id); } $text = str_replace('@DIFF@', $diff, $text); $subject = '[' . $conf['title'] . '] ' . $subject; $from = $conf['mailfrom']; $from = str_replace('@USER@', $_SERVER['REMOTE_USER'], $from); $from = str_replace('@NAME@', $INFO['userinfo']['name'], $from); $from = str_replace('@MAIL@', $INFO['userinfo']['mail'], $from); mail_send($to, $subject, $text, $from, '', $bcc); }