'); SDV($FoxRecipient, XL('Mail Recipient')); SDV($FoxNotifyHeaders, ''); SDV($FoxNotifyParameters, ''); SDV($FoxNotifyBodyHeadingFmt, "Recent $WikiTitle posts: \n"); SDV($FoxNotifyBodyFmt, "\$FoxNotifyBodyHeadingFmt\n" ."\$FoxNotifyItems\n"); SDV($FoxNotifyTimeFmt, $TimeFmt); SDV($FoxNotifyTemplatePageFmt, "$FoxNotifyListsGroup.FoxNotifyTemplates"); SDV($FoxNotifyItemFmt, "* $ScriptUrl/{\$FullName} . . . \$PostTime by {\$LastModifiedBy} \n"); if (@$EnableFoxNotifyHTMLEmail) $FoxNotifyHeaders = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; if (@$FoxNotifyFrom) $FoxNotifyHeaders = "From: $FoxNotifyFrom\r\n$FoxNotifyHeaders"; $EditFunctions[] = 'FoxPostNotify'; function FoxPostNotify($pagename) { global $IsPagePosted; $req = FoxRequestArgs($_POST); if ($IsPagePosted) register_shutdown_function('FoxNotifyUpdate', $pagename, getcwd(), $req); } ## check if we need to do notifications if ($action != 'edit' && $action!='foxpost' && $action!='foxdelete' && $action!='comment') FoxNotifyActionCheck($pagename); function FoxNotifyActionCheck($pagename) { global $FoxNotifyFile, $Now, $LastModTime; $nfp = @fopen($FoxNotifyFile, 'r'); if (!$nfp) return; $nextevent = fgets($nfp); fclose($nfp); if ($Now < $nextevent && $LastModTime < filemtime($FoxNotifyFile)) return; register_shutdown_function('FoxNotifyUpdate', $pagename, getcwd(), ''); } ## handle mailing of notifications function FoxNotifyUpdate($pagename, $dir, $fx) { global $FoxNotifyList, $FoxNotifyLists, $FoxGeneralNotifyList, $FoxNotifyFile, $IsPagePosted, $FmtV, $FoxNotifyTimeFmt, $FoxNotifyItemFmt, $FoxNotifyTemplatePageFmt, $FoxNotifyListsGroup, $FoxNotifySquelch, $FoxNotifyDelay, $Now, $SearchPatterns, $WikiTitle, $FoxRecipient, $FoxNotifySubjectFmt, $FoxNotifyBodyFmt, $FoxNotifyBodyHeadingFmt, $FoxNotifyHeaders, $FoxNotifyParameters, $EnableFoxNotifyHTMLEmail, $WikiTitle; $abort = ignore_user_abort(true); if ($dir) { flush(); chdir($dir); } $GLOBALS['EnableRedirect'] = 0; ## Read in the current notify configuration, merge notify lines from all list pages $fnlines = (array)@$FoxNotifyList; $FoxNotifyLists[] = $FoxGeneralNotifyList; foreach($FoxNotifyLists as $fnl) { $pn = FmtPageName($fnl, $pagename); $npage = ReadPage($pn, READPAGE_CURRENT); if(isset($npage['text'])) preg_match_all('/^[\s*:#->]*(notify[:=].*)/m', $npage['text'], $nline); else continue; $nline = $nline[1]; $fnlines = array_merge($fnlines, $nline); if ($fnlines=="") return; } ## make sure other processes are locked out Lock(2); ## let's load the current .notifylist table $nfile = FmtPageName($FoxNotifyFile, $pagename); $nfp = @fopen($nfile, 'r'); if ($nfp) { ## get our current squelch and delay timestamps clearstatcache(); $sz = filesize($nfile); list($nextevent, $firstpost) = explode(' ', rtrim(fgets($nfp, $sz))); ## restore our notify array $notify = unserialize(fgets($nfp, $sz)); fclose($nfp); } if (!is_array($notify)) $notify = array(); ## get newly posted page information if ($IsPagePosted) { $page = ReadPage($pagename, READPAGE_CURRENT); $FmtV['$PostTime'] = PSFT($FoxNotifyTimeFmt, $Now); if ($firstpost < 1) $firstpost = $Now; // retrieve formats from template $tpname = FmtPageName($FoxNotifyTemplatePageFmt, $pagename); if(PageExists($tpname)) { $tpage = ReadPage($tpname, READPAGE_CURRENT); $tsubject = trim(TextSection($tpage['text'], '#subject'),"\r\n"); $tbodyheading = trim(TextSection($tpage['text'], '#heading'),"\r\n"); } if(!isset($tsubject)) $tsubject = $FoxNotifySubjectFmt; $tsubject = FmtPageName($tsubject, $pagename); $subject = FoxTemplateEngine($pagename, $tsubject, $fx, '','', 'FoxNotify'); if(isset($tbodyheading)) $FoxNotifyBodyHeadingFmt = $tbodyheading; } foreach($fnlines as $n) { $opt = ParseArgs($n); if (isset($opt['notify'])) $mailto = preg_split('/[\s,]+/', $opt['notify']); if (!$mailto) continue; if (isset($fx['foxsendto']) && in_array('foxsendto', $mailto)) { $skey = array_search('foxsendto', $mailto); $mailto[$skey] = $fx['foxsendto']; } if (isset($opt['recipient'])) foreach($mailto as $m) $toName[$m] = $opt['recipient']; if (isset($opt['squelch'])) foreach($mailto as $m) $squelch[$m] = $opt['squelch']; if (!$IsPagePosted) continue; if (isset($opt['link'])) { $link = MakePageName($pagename, $opt['link']); if (!preg_match("/(^|,)$link(,|$)/i", $page['targets'])) continue; } $pats = @(array)$SearchPatterns[$opt['list']]; if (isset($opt['group'])) $pats[] = FixGlob($opt['group'], '$1$2.*'); if (isset($opt['name'])) $pats[] = FixGlob($opt['name'], '$1*.$2'); if ($pats && !MatchPageNames($pagename, $pats)) continue; if (isset($opt['trail'])) { $trail = ReadTrail($pagename, $opt['trail']); for ($i=0; $i= count($trail)) continue; } //try to load template from template page $tpl = @$opt['template']; if (!$tpl) $tpl = @$opt['format']; if (!$tpl) $tpl = '#default'; if($tpage) $titem = trim(TextSection($tpage['text'], $tpl),"\r\n"); // replace any {$$var} with values from input fields global $EnablePostDirectives; $EnablePostDirectives = 1; if(@$_GET['csum']) $_POST['csum'] = $_GET['csum']; #show($fx,'fx'); $tg = array('mail'); $titem = FoxTemplateEngine($pagename, $titem, $fx, $tg, '', 'FoxNotify'); if(!$titem) $titem = $FoxNotifyItemFmt; $item = urlencode(FmtPageName($titem, $pagename)); foreach ($mailto as $m) $notify[$m][] = $item; } $nnow = time(); if ($nnow < $firstpost + $FoxNotifyDelay) $nextevent = $firstpost + $FoxNotifyDelay; else { $firstpost = 0; $nextevent = $nnow + 86400; $mailto = array_keys($notify); $body = FmtPageName($FoxNotifyBodyFmt, $pagename); $headers = FmtPageName($FoxNotifyHeaders, $pagename); foreach ($mailto as $m) { $msquelch = @$notify[$m]['lastmail'] + ((@$squelch[$m]) ? $squelch[$m] : $FoxNotifySquelch); if ($nnow < $msquelch) { if ($msquelch < $nextevent && count($notify[$m])>1) $nextevent = $msquelch; continue; } unset($notify[$m]['lastmail']); if (!$notify[$m]) { unset($notify[$m]); continue; } $item = urldecode(implode("\n", $notify[$m])); $mbody = str_replace('$FoxNotifyItems', $item, $body); if(isset($toName[$m])) $mbody = str_replace($FoxRecipient, $toName[$m], $mbody); if (@$EnableFoxNotifyHTMLEmail) $mbody = MarkupToHTML($pagename, $mbody); #DEBUG echo "$m, $subject, $mbody, $headers, $FoxNotifyParameters"; exit; if (isset($FoxNotifyParameters)) mail($m, $subject, $mbody, $headers, $FoxNotifyParameters); else mail($m, $subject, $mbody, $headers); $notify[$m] = array('lastmail' => $nnow); } } ## save the updated notify status $nfp = @fopen($nfile, "w"); if($nfp) { fputs($nfp, "$nextevent $firstpost\n"); fputs($nfp, serialize($notify) . "\n"); fclose($nfp); } Lock(0); return true; } /// EOF