From 5b75cd1f5c479ada468fbf62a733c54edad152f1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 5 Jan 2010 14:14:00 +0100 Subject: New mail subscription with digest --- lib/exe/indexer.php | 70 ++++++++++++++++++++++++++++++++++++++++++++ lib/exe/js.php | 1 + lib/scripts/subscriptions.js | 46 +++++++++++++++++++++++++++++ lib/tpl/default/design.css | 14 +++++++++ lib/tpl/default/main.php | 1 - 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 lib/scripts/subscriptions.js (limited to 'lib') 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(); @@ -334,6 +335,75 @@ function runSitemapper(){ return true; } +/** + * Send digest and list mails for all subscriptions which are in effect for the + * current page + * + * @author Adrian Lang + */ +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 * 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 + */ + +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();
- -- cgit v1.2.3 From 8881fcc99a05f20da8fdd0f1c52f801fd84a8bb7 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 19 Nov 2009 15:25:25 +0100 Subject: Add events to subscription. --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index eb1556e1d..70aa607a9 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -399,7 +399,7 @@ function sendDigest() { $lastupdate); } // Update notification time. - subscription_set($id, $user, $style, true); + subscription_set($user, $id, $style, time(), true); } } } -- cgit v1.2.3 From 3a5a6f4fe4a9f768f5c6418ba0694d67594ed701 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 23 Nov 2009 17:16:03 +0100 Subject: correctly handle permissions in digest mailer Ignore-this: c34455078907459a846cf7f00e2b586b darcs-hash:20091123161603-6e07b-927477d6ca50e665228487eb0d3ce9787dbe455b.gz --- lib/exe/indexer.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 70aa607a9..1766c54f1 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -342,19 +342,24 @@ function runSitemapper(){ * @author Adrian Lang */ function sendDigest() { - require_once DOKU_INC . 'inc/subscription.php'; 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; @@ -363,13 +368,11 @@ function sendDigest() { // 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) { + + // Work as the user to make sure ACLs apply correctly + $USERINFO = $auth->getUserData($user); + $_SERVER['REMOTE_USER'] = $user; + if ($USERINFO === false) { continue; } @@ -389,6 +392,8 @@ function sendDigest() { } // TODO: Handle duplicate subscriptions. } else { + if(auth_quickacl($id) < AUTH_READ) continue; + $meta = p_get_metadata($id); $rev = $meta['last_change']['date']; if ($rev < $lastupdate) { @@ -402,6 +407,10 @@ function sendDigest() { subscription_set($user, $id, $style, time(), true); } } + + // restore current user info + $USERINFO = $olduinfo; + $_SERVER['REMOTE_USER'] = $olduser; } /** -- cgit v1.2.3 From 2f27189ab6f07352f435e91bab0c28dfc4899583 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 24 Nov 2009 12:58:05 +0100 Subject: wrong function name fixed Ignore-this: b74163181c2e41d3be022a6185f3e1c1 darcs-hash:20091124115805-6e07b-e808cf44a00a65ff8c70cc7e8de4dfedadf96cbd.gz --- lib/exe/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1766c54f1..53f2c129d 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -392,7 +392,7 @@ function sendDigest() { } // TODO: Handle duplicate subscriptions. } else { - if(auth_quickacl($id) < AUTH_READ) continue; + if(auth_quickaclcheck($id) < AUTH_READ) continue; $meta = p_get_metadata($id); $rev = $meta['last_change']['date']; -- cgit v1.2.3 From 056c20495937fe45fe0f7204b112dbfe6931a855 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 30 Nov 2009 14:03:11 +0100 Subject: nicer subscription styles Ignore-this: e1b3b815b5ebb0da320bff997c4fed4b darcs-hash:20091130130311-6e07b-03ccfc52abb3dcc0764eed5784d81f8416841328.gz --- lib/scripts/subscriptions.js | 6 +++--- lib/tpl/default/_subscription.css | 21 +++++++++++++++++++++ lib/tpl/default/design.css | 13 ------------- lib/tpl/default/style.ini | 7 ++++--- 4 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 lib/tpl/default/_subscription.css (limited to 'lib') diff --git a/lib/scripts/subscriptions.js b/lib/scripts/subscriptions.js index 9f602dde8..2af4ee8c4 100644 --- a/lib/scripts/subscriptions.js +++ b/lib/scripts/subscriptions.js @@ -5,7 +5,7 @@ */ addInitEvent(function () { - var form = $('subscribe'); + var form = $('subscribe__form'); if (!form) { return; } @@ -31,13 +31,13 @@ addInitEvent(function () { var inputs = form.getElementsByTagName('input'); for (var i = 0; i < inputs.length ; ++i) { switch (inputs[i].name) { - case 'subscribe_target': + case 'sub_target': inputs[i].addEventListener('change', update_state, false); if (inputs[i].checked) { cur_sel = inputs[i]; } break; - case 'subscribe_style': + case 'sub_style': styleradios[inputs[i].value] = inputs[i]; break; } diff --git a/lib/tpl/default/_subscription.css b/lib/tpl/default/_subscription.css new file mode 100644 index 000000000..0792c8c21 --- /dev/null +++ b/lib/tpl/default/_subscription.css @@ -0,0 +1,21 @@ +/** + * Styles for the subscription page + */ + +form#subscribe__form { + display: block; + width: 300px; + text-align: center; +} + +form#subscribe__form fieldset { + text-align: left; + margin: 0.5em 0; +} + +form#subscribe__form label { + display:block; + margin: 0 0.5em 0.5em; +} + + diff --git a/lib/tpl/default/design.css b/lib/tpl/default/design.css index 02804256c..9c3e7b119 100644 --- a/lib/tpl/default/design.css +++ b/lib/tpl/default/design.css @@ -834,16 +834,3 @@ div.dokuwiki div.imagemeta img.thumb { 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/style.ini b/lib/tpl/default/style.ini index dfd5500fa..84d04e743 100644 --- a/lib/tpl/default/style.ini +++ b/lib/tpl/default/style.ini @@ -10,9 +10,10 @@ layout.css = screen design.css = screen style.css = screen -media.css = screen -_admin.css = screen -_linkwiz.css = screen +media.css = screen +_admin.css = screen +_linkwiz.css = screen +_subscription.css = screen rtl.css = rtl print.css = print -- cgit v1.2.3 From 34240a5903c7499900c8ecf0a5592d28f67aaf46 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 30 Nov 2009 14:50:40 +0100 Subject: Fix $info var reference in digest send darcs-hash:20091130135040-e4919-40b6614fe28ea07dc5796661ddda6d005264ddbc.gz --- lib/exe/indexer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 53f2c129d..84eb9d482 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -384,11 +384,11 @@ function sendDigest() { } if ($style === 'digest') { foreach($changes as $change) { - subscription_send_digest($info['mail'], $change, + subscription_send_digest($USERINFO['mail'], $change, $lastupdate); } } elseif ($style === 'list') { - subscription_send_list($info['mail'], $changes, $id); + subscription_send_list($USERINFO['mail'], $changes, $id); } // TODO: Handle duplicate subscriptions. } else { @@ -400,7 +400,7 @@ function sendDigest() { // There is no new revision. continue; } - subscription_send_digest($info['mail'], $meta['last_change'], + subscription_send_digest($USERINFO['mail'], $meta['last_change'], $lastupdate); } // Update notification time. -- cgit v1.2.3 From e419596a1552d52670605ef4c380757d6fd0ffa7 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 2 Dec 2009 13:16:18 +0100 Subject: =?UTF-8?q?Use=20click=20event=20in=20subscription=20JS,=20use=20D?= =?UTF-8?q?W=E2=80=99s=20event=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit darcs-hash:20091202121618-e4919-e3c409aa3e6e24db89558a6e62b8c46df950f5b0.gz --- lib/scripts/subscriptions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/scripts/subscriptions.js b/lib/scripts/subscriptions.js index 2af4ee8c4..d701f258f 100644 --- a/lib/scripts/subscriptions.js +++ b/lib/scripts/subscriptions.js @@ -32,7 +32,7 @@ addInitEvent(function () { for (var i = 0; i < inputs.length ; ++i) { switch (inputs[i].name) { case 'sub_target': - inputs[i].addEventListener('change', update_state, false); + addEvent(inputs[i], 'click', update_state); if (inputs[i].checked) { cur_sel = inputs[i]; } -- cgit v1.2.3 From eee44352b2c73d56818600770b87f891b88a545f Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 12 Jan 2010 11:24:11 +0100 Subject: Add subscribe time to admin interface. --- lib/plugins/config/lang/en/lang.php | 1 + lib/plugins/config/settings/config.metadata.php | 1 + 2 files changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php index 25103278c..45b653680 100644 --- a/lib/plugins/config/lang/en/lang.php +++ b/lib/plugins/config/lang/en/lang.php @@ -130,6 +130,7 @@ $lang['gdlib'] = 'GD Lib version'; $lang['im_convert'] = 'Path to ImageMagick\'s convert tool'; $lang['jpg_quality'] = 'JPG compression quality (0-100)'; $lang['subscribers'] = 'Enable page subscription support'; +$lang['subscribe_time'] = 'Time after which subscription lists and digests are sent (sec); This should be larger than the time specified in recent_days.'; $lang['compress'] = 'Compact CSS and javascript output'; $lang['hidepages'] = 'Hide matching pages (regular expressions)'; $lang['send404'] = 'Send "HTTP 404/Page Not Found" for non existing pages'; diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 742faf387..da2ba4aef 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -148,6 +148,7 @@ $meta['htmlok'] = array('onoff'); $meta['phpok'] = array('onoff'); $meta['notify'] = array('email', '_multiple' => true); $meta['subscribers'] = array('onoff'); +$meta['subscribe_time'] = array('numeric'); $meta['locktime'] = array('numeric'); $meta['cachetime'] = array('numeric'); -- cgit v1.2.3