diff options
author | Adrian Lang <lang@cosmocode.de> | 2010-01-05 14:14:00 +0100 |
---|---|---|
committer | Adrian Lang <lang@cosmocode.de> | 2010-01-20 10:53:18 +0100 |
commit | 5b75cd1f5c479ada468fbf62a733c54edad152f1 (patch) | |
tree | 7ca6012d892aaef60cee7bc86b2f62ade43e03ce /lib | |
parent | b5ee21aa65a2f380e3b99ff5ea6ced48c1cb720e (diff) | |
download | rpg-5b75cd1f5c479ada468fbf62a733c54edad152f1.tar.gz rpg-5b75cd1f5c479ada468fbf62a733c54edad152f1.tar.bz2 |
New mail subscription with digest
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/indexer.php | 70 | ||||
-rw-r--r-- | lib/exe/js.php | 1 | ||||
-rw-r--r-- | lib/scripts/subscriptions.js | 46 | ||||
-rw-r--r-- | lib/tpl/default/design.css | 14 | ||||
-rw-r--r-- | lib/tpl/default/main.php | 1 |
5 files changed, 131 insertions, 1 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> 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', ); diff --git a/lib/scripts/subscriptions.js b/lib/scripts/subscriptions.js new file mode 100644 index 000000000..9f602dde8 --- /dev/null +++ b/lib/scripts/subscriptions.js @@ -0,0 +1,46 @@ +/** + * Hide list subscription style if target is a page + * + * @author Adrian Lang <lang@cosmocode.de> + */ + +addInitEvent(function () { + var form = $('subscribe'); + if (!form) { + return; + } + + var styleradios = {}; + + function update_state() { + if (!this.checked) { + return; + } + if (this.value.match(/:$/)) { + styleradios.list.parentNode.style.display = ''; + } else { + styleradios.list.parentNode.style.display = 'none'; + if (styleradios.list.checked) { + styleradios.digest.checked = 'checked'; + } + } + } + + var cur_sel = null; + + var inputs = form.getElementsByTagName('input'); + for (var i = 0; i < inputs.length ; ++i) { + switch (inputs[i].name) { + case 'subscribe_target': + inputs[i].addEventListener('change', update_state, false); + if (inputs[i].checked) { + cur_sel = inputs[i]; + } + break; + case 'subscribe_style': + styleradios[inputs[i].value] = inputs[i]; + break; + } + } + update_state.call(cur_sel); +}); diff --git a/lib/tpl/default/design.css b/lib/tpl/default/design.css index 4830a9e2c..02804256c 100644 --- a/lib/tpl/default/design.css +++ b/lib/tpl/default/design.css @@ -833,3 +833,17 @@ div.dokuwiki div.imagemeta img.thumb { float: left; margin-right: 0.1em; } + +form#subscribe p { + margin: 0.5em 0; +} + +form#subscribe label { + display:block; + margin: 0 0.5em 0.5em; +} + +form#subscribe fieldset, form#unsubscribe fieldset { + text-align:inherit; + margin: 0; +} diff --git a/lib/tpl/default/main.php b/lib/tpl/default/main.php index 67c3a00ba..b5717c009 100644 --- a/lib/tpl/default/main.php +++ b/lib/tpl/default/main.php @@ -117,7 +117,6 @@ if (!defined('DOKU_INC')) die(); </div> <div class="bar-right" id="bar__bottomright"> <?php tpl_button('subscribe')?> - <?php tpl_button('subscribens')?> <?php tpl_button('admin')?> <?php tpl_button('profile')?> <?php tpl_button('login')?> |