summaryrefslogtreecommitdiff
path: root/lib/exe/indexer.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-01-05 14:14:00 +0100
committerAdrian Lang <lang@cosmocode.de>2010-01-20 10:53:18 +0100
commit5b75cd1f5c479ada468fbf62a733c54edad152f1 (patch)
tree7ca6012d892aaef60cee7bc86b2f62ade43e03ce /lib/exe/indexer.php
parentb5ee21aa65a2f380e3b99ff5ea6ced48c1cb720e (diff)
downloadrpg-5b75cd1f5c479ada468fbf62a733c54edad152f1.tar.gz
rpg-5b75cd1f5c479ada468fbf62a733c54edad152f1.tar.bz2
New mail subscription with digest
Diffstat (limited to 'lib/exe/indexer.php')
-rw-r--r--lib/exe/indexer.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index 1c4128eb7..eb1556e1d 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -37,6 +37,7 @@ if ($evt->advise_before()) {
runIndexer() or
metaUpdate() or
runSitemapper() or
+ sendDigest() or
runTrimRecentChanges() or
runTrimRecentChanges(true) or
$evt->advise_after();
@@ -335,6 +336,75 @@ function runSitemapper(){
}
/**
+ * Send digest and list mails for all subscriptions which are in effect for the
+ * current page
+ *
+ * @author Adrian Lang <lang@cosmocode.de>
+ */
+function sendDigest() {
+ require_once DOKU_INC . 'inc/subscription.php';
+ 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;
+ foreach($subscriptions as $id => $users) {
+ foreach($users as $data) {
+ list($user, $style, $lastupdate) = $data;
+ $lastupdate = (int) $lastupdate;
+ if ($lastupdate + $conf['subscribe_interval'] > time()) {
+ // Less than a day passed since last update.
+ continue;
+ }
+ // TODO: Does that suffice for namespaces?
+ $info = $auth->getUserData($user);
+ if ($info === false) {
+ continue;
+ }
+ $level = auth_aclcheck($id, $user, $info['grps']);
+ if ($level < AUTH_READ) {
+ 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($info['mail'], $change,
+ $lastupdate);
+ }
+ } elseif ($style === 'list') {
+ subscription_send_list($info['mail'], $changes, $id);
+ }
+ // TODO: Handle duplicate subscriptions.
+ } else {
+ $meta = p_get_metadata($id);
+ $rev = $meta['last_change']['date'];
+ if ($rev < $lastupdate) {
+ // There is no new revision.
+ continue;
+ }
+ subscription_send_digest($info['mail'], $meta['last_change'],
+ $lastupdate);
+ }
+ // Update notification time.
+ subscription_set($id, $user, $style, true);
+ }
+ }
+}
+
+/**
* Formats a timestamp as ISO 8601 date
*
* @author <ungu at terong dot com>