changed git call from https to git readonly
[atutor.git] / mods / wiki / tools / cron.d / S80recentnotify.php
1 <?php
2 /*
3    Everybody who leaves a mail address on the "RecentNotify" page, will
4    get a summary of all made edits, once in a week (configured to 8 days
5    per default).
6 */
7
8 define("RECENTNOTIFY", "RecentNotify");   // special page name (w/ subscribers)
9 define("RECENTNOTIFY_DAYS", 8);           // in days
10
11
12 #-- do
13 if (RECENTNOTIFY_DAYS && ($data = ewiki_db::GET(RECENTNOTIFY))) {
14    echo "[$cron]: checking for " . RECENTNOTIFY . " subscribers\n";
15
16    #-- look up subscribers
17    ewiki_scan_wikiwords($data["content"], $uu, $_strip_email=0);
18    $subscribers = array();
19    if ($uu) foreach ($uu as $str=>$x) {
20       if (strpos($str, "@")) {
21          if (strpos($str, "notify:")!==false) {
22             $str = substr($str, strpos($str, ":"));
23          }
24          $subscribers[] = $str;
25       }
26    }
27    
28    #-- only calc the RC if we have at least one interested
29    if ($subscribers) {
30       echo "[$cron]: ".count($subscribers)." listed (".implode(", ", $subscribers).")\n";
31       $min_time = time() - RECENTNOTIFY_DAYS * 24 * 3600;
32       $rc = array();
33       $vers = array();
34       $mail = "";
35
36       #-- find pages changed in given timeframe
37       $all = ewiki_db::GETALL(array("id", "version", "flags", "lastmodified"));
38       while ($row = $all->get(0, 0x137f)) {
39
40          if ($row["lastmodified"] >= $min_time) {
41             $rc[$row["id"]] = $row["lastmodified"];
42             $vers[$row["id"]] = $row["version"];
43          }
44       }
45
46       #-- go through rc list
47       echo "[$cron]: generating RC list\n";
48       arsort($rc);
49       $lastdatestr = "";
50       do {
51
52          #-- get entry
53          reset($rc);
54          list($id, $lm) = each($rc);
55          $ver = $vers[$id];
56          array_shift($rc);
57          
58          #-- output
59          $row = ewiki_db::GET($id, $ver);
60          $m_ver = $row["version"];
61          ($m_log = $row["meta"]["log"]) and ($m_log = " . [{$m_log}] . .");
62          $m_author = $row["author"];
63          $m_ua = $row["meta"]["user-agent"];
64          $m_time = strftime("%H:%M", $lm);
65          $m_flags = "";
66          if ($row["flags"] & EWIKI_DB_F_MINOR) {
67             $m_flags .= " MINOR EDIT";
68          }
69          if ($row["flags"] & EWIKI_DB_F_APPENDONLY) {
70             $m_flags .= " (append-only)";
71          }
72          if ($row["flags"] & EWIKI_DB_F_HIDDEN) {
73             $m_flags .= " (hidden page)";
74          }
75          $datestr = strftime("%Y-%m-%d, %a", $lm);
76          if ($lastdatestr != $datestr) {
77             $lastdatestr = $datestr;
78             $mail .= "\n$datestr\n";
79          }
80          $mail .= "ยท {$id} - [{$m_ver}]{$m_flags} {$m_time} . . .{$m_log} by {$m_author} / {$m_ua}\n";
81
82          #-- check previous version of this page
83          if (($ver--) && ($row = ewiki_db::GET($id, $ver))) {
84             if ($row["lastmodified"] >= $min_time) {
85                $vers[$id] = $row["version"];
86                $rc[$id] = $row["lastmodified"];
87                arsort($rc);
88             }
89          }
90       }
91       while ($rc);
92       
93       #-- send it
94       echo "$mail";
95       $subj = RECENTNOTIFY ." on ". EWIKI_NAME;
96       $to = implode(", ", $subscribers);
97       $mail = "This is the full list of latest changes on " . EWIKI_NAME . ".\n"
98             . ewiki_script_url("", EWIKI_PAGE_INDEX) . "\n"
99             . "Unsubscribe yourself on " . ewiki_script_url("edit", RECENTNOTIFY) . "\n"
100             . "\n"
101             . $mail
102             . "\n\n-- \nThere is no Web like WikiWikiWeb.\n";
103       mail($to, $subj, $mail);
104    }
105 }
106
107
108 ?>