diff options
author | Adrian Lang <lang@cosmocode.de> | 2010-01-20 10:56:01 +0100 |
---|---|---|
committer | Adrian Lang <lang@cosmocode.de> | 2010-01-20 10:56:01 +0100 |
commit | 7d723f3d24511105ce37006f9439632c3d8f915e (patch) | |
tree | 605809aace3e368d953466f76425b41d56fa1b38 /lib/exe | |
parent | 1c64eaeaa3295062b0a4e9b20b772274cd86ca42 (diff) | |
parent | eee44352b2c73d56818600770b87f891b88a545f (diff) | |
download | rpg-7d723f3d24511105ce37006f9439632c3d8f915e.tar.gz rpg-7d723f3d24511105ce37006f9439632c3d8f915e.tar.bz2 |
Merge branch 'subscription'
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/indexer.php | 79 | ||||
-rw-r--r-- | lib/exe/js.php | 1 |
2 files changed, 80 insertions, 0 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1c4128eb7..84eb9d482 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,84 @@ 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() { + echo 'sendDigest(): start'.NL; + global $ID; + global $conf; + if (!$conf['subscribers']) { + return; + } + require_once DOKU_INC . 'inc/subscription.php'; + $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) { + 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; + } + + // 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); + } + } + + // restore current user info + $USERINFO = $olduinfo; + $_SERVER['REMOTE_USER'] = $olduser; +} + +/** * Formats a timestamp as ISO 8601 date * * @author <ungu at terong dot com> diff --git a/lib/exe/js.php b/lib/exe/js.php index 38fda1789..8648bf18f 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -53,6 +53,7 @@ function js_out(){ DOKU_INC.'lib/scripts/edit.js', DOKU_INC.'lib/scripts/linkwiz.js', DOKU_INC.'lib/scripts/media.js', + DOKU_INC.'lib/scripts/subscriptions.js', DOKU_TPLINC.'script.js', ); |