/** * Send digest and list mails for all subscriptions which are in effect for the * current page * * @author Adrian Lang <*****@*****.**> */ function sendDigest() { echo 'sendDigest(): started' . NL; global $ID; global $conf; if (!$conf['subscribers']) { echo 'sendDigest(): disabled' . NL; return false; } $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true)); /** @var auth_basic $auth */ global $auth; global $lang; global $conf; global $USERINFO; // remember current user info $olduinfo = $USERINFO; $olduser = $_SERVER['REMOTE_USER']; foreach ($subscriptions as $id => $users) { if (!subscription_lock($id)) { continue; } foreach ($users as $data) { list($user, $style, $lastupdate) = $data; $lastupdate = (int) $lastupdate; if ($lastupdate + $conf['subscribe_time'] > time()) { // Less than the configured time period passed since last // update. continue; } // Work as the user to make sure ACLs apply correctly $USERINFO = $auth->getUserData($user); $_SERVER['REMOTE_USER'] = $user; if ($USERINFO === false) { continue; } if (substr($id, -1, 1) === ':') { // The subscription target is a namespace $changes = getRecentsSince($lastupdate, null, getNS($id)); } else { if (auth_quickaclcheck($id) < AUTH_READ) { continue; } $meta = p_get_metadata($id); $changes = array($meta['last_change']); } // Filter out pages only changed in small and own edits $change_ids = array(); foreach ($changes as $rev) { $n = 0; while (!is_null($rev) && $rev['date'] >= $lastupdate && ($_SERVER['REMOTE_USER'] === $rev['user'] || $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) { $rev = getRevisions($rev['id'], $n++, 1); $rev = count($rev) > 0 ? $rev[0] : null; } if (!is_null($rev) && $rev['date'] >= $lastupdate) { // Some change was not a minor one and not by myself $change_ids[] = $rev['id']; } } if ($style === 'digest') { foreach ($change_ids as $change_id) { subscription_send_digest($USERINFO['mail'], $change_id, $lastupdate); } } elseif ($style === 'list') { subscription_send_list($USERINFO['mail'], $change_ids, $id); } // TODO: Handle duplicate subscriptions. // Update notification time. subscription_set($user, $id, $style, time(), true); } subscription_unlock($id); } // restore current user info $USERINFO = $olduinfo; $_SERVER['REMOTE_USER'] = $olduser; echo 'sendDigest(): finished' . NL; return true; }
/** * Return a string with the email addresses of all the * users subscribed to a page * * This is the default action for COMMON_NOTIFY_ADDRESSLIST. * * @param array $data Containing $id (the page id), $self (whether the author * should be notified, $addresslist (current email address * list) * * @author Steven Danz <*****@*****.**> * @author Adrian Lang <*****@*****.**> */ function subscription_addresslist(&$data) { global $conf; global $auth; $id = $data['id']; $self = $data['self']; $addresslist = $data['addresslist']; if (!$conf['subscribers'] || $auth === null) { return ''; } $pres = array('style' => 'every', 'escaped' => true); if (!$self && isset($_SERVER['REMOTE_USER'])) { $pres['user'] = '******' . preg_quote_cb($_SERVER['REMOTE_USER']) . '(?: |$))\\S+)'; } $subs = subscription_find($id, $pres); $emails = array(); foreach ($subs as $by_targets) { foreach ($by_targets as $sub) { $info = $auth->getUserData($sub[0]); if ($info === false) { continue; } $level = auth_aclcheck($id, $sub[0], $info['grps']); if ($level >= AUTH_READ) { if (strcasecmp($info['mail'], $conf['notify']) != 0) { $emails[$sub[0]] = $info['mail']; } } } } $data['addresslist'] = trim($addresslist . ',' . implode(',', $emails), ','); }
/** * Send digest and list mails for all subscriptions which are in effect for the * current page * * @author Adrian Lang <*****@*****.**> */ function sendDigest() { echo 'sendDigest(): start' . NL; global $ID; global $conf; if (!$conf['subscribers']) { return; } $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true)); global $auth; global $lang; global $conf; global $USERINFO; // remember current user info $olduinfo = $USERINFO; $olduser = $_SERVER['REMOTE_USER']; foreach ($subscriptions as $id => $users) { if (!subscription_lock($id)) { continue; } foreach ($users as $data) { list($user, $style, $lastupdate) = $data; $lastupdate = (int) $lastupdate; if ($lastupdate + $conf['subscribe_time'] > time()) { // Less than the configured time period passed since last // update. continue; } // Work as the user to make sure ACLs apply correctly $USERINFO = $auth->getUserData($user); $_SERVER['REMOTE_USER'] = $user; if ($USERINFO === false) { continue; } if (substr($id, -1, 1) === ':') { // The subscription target is a namespace $changes = getRecentsSince($lastupdate, null, getNS($id)); if (count($changes) === 0) { continue; } if ($style === 'digest') { foreach ($changes as $change) { subscription_send_digest($USERINFO['mail'], $change, $lastupdate); } } elseif ($style === 'list') { subscription_send_list($USERINFO['mail'], $changes, $id); } // TODO: Handle duplicate subscriptions. } else { if (auth_quickaclcheck($id) < AUTH_READ) { continue; } $meta = p_get_metadata($id); $rev = $meta['last_change']['date']; if ($rev < $lastupdate) { // There is no new revision. continue; } subscription_send_digest($USERINFO['mail'], $meta['last_change'], $lastupdate); } // Update notification time. subscription_set($user, $id, $style, time(), true); } subscription_unlock($id); } // restore current user info $USERINFO = $olduinfo; $_SERVER['REMOTE_USER'] = $olduser; }