3 # The otherwise invisible markup [notify:you@there.net] will trigger a
4 # mail, whenever a page is changed. The TLD decides in which language
5 # the message will be delivered. One can also append the lang code after
6 # a comma or semicolon behind the mail address to set it explicitely:
7 # [notify:me@here.org,de] or [notify:you@there.net;eo]
9 # Nevertheless English will be used as the default automagically, if
10 # nothing else was specified, no need to worry about this.
12 # additional features:
14 # * [notify:icq:123456789] - suddenly ICQ.com took the pager service down
16 # To include a diff, just set the following constant. Also use it to
17 # define the minimum number of changed bytes that are necessary to
18 # result in a notification mail. Only use it with Linux/UNIX.
20 define("EWIKI_NOTIFY_WITH_DIFF", 0); #-- set it to 100 or so
21 define("EWIKI_NOTIFY_SENDER",'ewiki');
25 $ewiki_plugins["edit_hook"][] = "ewiki_notify_edit_hook";
26 $ewiki_plugins["format_source"][] = "ewiki_format_remove_notify";
27 $ewiki_config["interwiki"]["notify"] = "mailto:";
30 #-- email message text ---------------------------------------------------
31 $ewiki_t["en"]["NOTIFY_SUBJECT"] = '"$id" was changed [notify:...]';
32 $ewiki_t["en"]["NOTIFY_BODY"] = <<<_END_OF_STRING
35 A WikiPage has changed and you requested to be notified when this
36 happens. The changed page was '\$id' and can be found
40 To stop messages like this please strip the [notify:...] with your address
41 from the page edit box at \$edit_link
43 (\$wiki_title on http://\$server/)
49 $ewiki_t["de"]["NOTIFY_SUBJECT"] = '"$id" wurde geändert [notify:...]';
50 $ewiki_t["de"]["NOTIFY_BODY"] = <<<_END_OF_STRING
53 Eine WikiSeite hat sich geändert
, und du wolltest ja unbedingt wissen
,
54 wenn das passiert
. Die geänderte Seite war
'\$id' und
55 ist leicht zu finden unter folgender URL
:
58 Wenn du diese Benachrichtigungen nicht mehr bekommen willst
, solltest du
59 deine
[notify
:...]-Adresse aus der entsprechenden Edit
-Box herauslöschen
:
62 (\
$wiki_title auf http
://\$server/)
67 #----------------------------------------------------------------------------
72 function ewiki_notify_edit_hook($id, $data, &$hidden_postdata) {
74 global $ewiki_t, $ewiki_plugins;
77 if (!isset($_REQUEST["save"])) {
81 $mailto = ewiki_notify_links($data["content"], 0);
83 if (!count($mailto)) {
89 if (EWIKI_NOTIFY_WITH_DIFF
&& (DIRECTORY_SEPARATOR
=="/")) {
91 #-- save page versions temporarily as files
92 $fn1 = EWIKI_TMP
."/ewiki.tmp.notify.diff.".md5($data["content"]);
93 $fn2 = EWIKI_TMP
."/ewiki.tmp.notify.diff.".md5($_REQUEST["content"]);
94 $f = fopen($fn1, "w");
95 fwrite($f, $data["content"]);
97 $f = fopen($fn2, "w");
98 fwrite($f, $_REQUEST["content"]);
100 #-- set mtime of the old one (GNU diff will report it)
101 touch($fn1, $data["lastmodified"]);
103 #-- get diff output, rm temp files
105 if ($f = popen("$diff_exe --normal --ignore-case --ignore-space-change $fn1 $fn2 2>&1 ", "r")) {
107 $diff .= fread($f, 16<<10);
110 $diff_failed = !strlen($diff)
111 ||
(strpos($diff, "Files ") === 0);
113 #-- do not [notify:] if changes were minimal
114 if ((!$diff_failed) && (strlen($diff) < EWIKI_NOTIFY_WITH_DIFF
)) {
115 #echo("WikiNotice: no notify, because too few changes (" .strlen($diff)." byte)\n");
119 $diff = "\n\n-----------------------------------------------------------------------------\n\n"
124 #echo("WikiWarning: diff failed in notify module\n");
135 #-- separate addresses into (TLD) groups
136 $mailto_lang = array(
138 foreach ($mailto as $m) {
142 #-- remove lang selection trailer
143 $m = strtok($m, ",");
144 if ($uu = strtok(",")) {
147 $m = strtok($m, ";");
148 if ($uu = strtok(";")) {
152 #-- else use TLD as language code
154 $r = strrpos($m, ".");
155 $lang = substr($m, $r+
1);
161 if (substr($m, 0, 4) == "icq:") {
162 $m = substr($m, 4) . "@pager.icq.com";
165 $mailto_lang[$lang][] = $m;
168 #-- go thru email address groups
169 foreach ($mailto_lang as $lang=>$a_mailto) {
171 $pref_langs = array_merge(array(
173 ), $ewiki_t["languages"]);
175 ($server = $_SERVER["HTTP_HOST"]) or
176 ($server = $_SERVER["SERVER_NAME"]);
177 $s_4 = "http".($_SERVER['HTTPS'] == "on" ?
's':'')."://" . $server . $_SERVER["REQUEST_URI"];
178 $link = str_replace("edit/$id", "$id", $s_4);
180 $m_text = ewiki_t("NOTIFY_BODY", array(
184 "server_admin" => $_SERVER["SERVER_ADMIN"],
186 "wiki_title" => EWIKI_PAGE_INDEX
,
190 $m_from = EWIKI_NOTIFY_SENDER
."@$server";
191 $m_subject = ewiki_t("NOTIFY_SUBJECT", array(
195 $m_to = implode(", ", $a_mailto);
197 mail($m_to, $m_subject, $m_text, "From: \"$s_2\" <$m_from>\nX-Mailer: ErfurtWiki/".EWIKI_VERSION
);
204 function ewiki_notify_links(&$source, $strip=1) {
207 if (strlen($source) > 10)
208 while (($l = @strpos
($source, "[notify:", $l)) !== false) {
209 $r = strpos($source, "]", $l);
210 $str = substr($source, $l, $r +
1 - $l);
211 if (!strpos("\n", $str)) {
212 $links[] = trim(substr($str, 8, -1));
214 $source = substr($source, 0, $l) . substr($source, $r +
1);
224 function ewiki_format_remove_notify(&$source) {
225 ewiki_notify_links($source, 1);