[Pmwiki-users] PATCH extending mailposts to format the posts

Thomas -Balu- Walter list+pmwiki-users
Thu Mar 18 07:27:02 CST 2004


I've just created a little patch that will allow you to specify the
format of each post in the mailmessage. 

After applying the patch you can change the configuration variable
$MailPostsFmt to include the following placeholders:

    $PageName - will be replaced with the name of the page
    $Time - time formatted with $MailPostsTimeFmt
    $Author - name of changing author

The default look tries to go after the format of RecentChanges:
 * $PageName . . . $Time by $Author

Pm, I tried to make my code follow your compressed coding standard :).
Please have a look at the code and notify me of any things I might not
have thought of.

All others, feel free to test and let me know what you think of this
change.

     Balu
-------------- next part --------------
--- pmwiki-0.6.9/scripts/mailposts.php	Thu Feb 26 19:27:23 2004
+++ scripts/mailposts.php	Thu Mar 18 15:13:07 2004
@@ -37,6 +37,16 @@
     $MailPostsFunction - If the default PHP mail function isn't working
        for you, then you can define your own mail function here or you
        can try "MailPostsSendmail".  
+
+    Changed 2004-03-18 by Balu:
+    Added the possibility to format the posts in the mailmessage:
+    $MailPostsFmt - how each post gets displayed in the mail
+       allows the following parameters:
+       $PageName - will be replaced with the name of the page
+       $Time - time formatted with $MailPostsTimeFmt
+       $Author - name of changing author
+    $MailPostsPlaceholder - an array containing the above placeholders
+       and their replacements
 */
 
 SDV($MailPostsDelay,0);
@@ -46,15 +56,27 @@
   ."  ($ScriptUrl/Main/AllRecentChanges)\n\n\$MailPostsList\n");
 SDV($MailPostsSubject,"$WikiTitle recent wiki posts");
 SDV($MailPostsFunction,"mail");
-SDV($MailPostsTimeFmt,"$TimeFmt - ");
+SDV($MailPostsTimeFmt,"$TimeFmt");
 SDV($MailPostsHeaders,'');
+SDV($MailPostsFmt,' * $PageName . . . $Time by $Author');
+SDVA($MailPostsPlaceholder, array(
+  '$Time'=>strftime($MailPostsTimeFmt,$Now),
+  '$PageName'=>$pagename,
+  '$Author'=>$Author));
 if (@$MailPostsFrom) 
   $MailPostsHeaders = "From: $MailPostsFrom\r\n$MailPostsHeaders";
 
 if ($action=='post' || @$HTTP_POST_VARS['post']) {
   Lock(2);
   $fp = @fopen($MailPostsFile,"a");
-  if ($fp) { fputs($fp,"$Now $pagename\n"); fclose($fp); }
+  if ($fp) { 
+    $p=str_replace(
+      array_keys($MailPostsPlaceholder),
+      array_values($MailPostsPlaceholder),
+      $MailPostsFmt);
+    fputs($fp,"$Now $p\n"); 
+    fclose($fp); 
+  }
   Lock(0);
 }
 
@@ -63,14 +85,15 @@
 if (!$fp) return;
 $oldestpost = $Now+1; $mailpost=array();
 while (!feof($fp)) {
-  @(list($t,$p) = explode(' ',rtrim(fgets($fp,1024))));
+  if (!preg_match('/^(\d+) (.*)/',rtrim(fgets($fp,1024)), $x)) continue;
+  $t=$x[1]; $p=$x[2];
   if (!$t) continue;
   if ($p=='#lastmailed') {
     if ($t > $Now-$MailPostsSquelch) { fclose($fp); return; }
     continue;
   }
   Lock(2);
-  array_push($mailpost,strftime($MailPostsTimeFmt,$t)."$p\n");
+  array_push($mailpost,"$p\n");
   if ($t<$oldestpost) $oldestpost=$t;
 }
 fclose($fp);


More information about the pmwiki-users mailing list