[pmwiki-users] ZAP newsletter module

The Editor editor at fast.st
Fri Nov 3 05:58:04 CST 2006


Well, the zapnews module is nearly ready.  I still am looking for
someway to run the sendnews( ) function without tying up the page.  If
no one has a suggestion for how to do that, I guess I'll pursue cron.

I would have liked a solution without cron--as my home system is
XP/apache.  And I don't have cron capabilities at home.  But maybe
that's also why none of the other options I've tried work.

For anyone interested, I pasted below the code I've pulled together
for processing any wiki pages in the mailing list queue
(group=Temp-Newsletters).  I've tried to write it using no PmWiki
functions or variables so it could run independently.  Creation of the
queues is all done separately in zap.

If anyone spots any problems, I'd appreciate input.  I'm not really
even sure how to debug this until I can find a way to run it. I guess
I can make it into a function and run it through some markup for
testing, then upload and try and get cron to work.
I thought about simply running it in an invisible frame on my site.

Also, not sure how access and all works in php.  If cron or a
non-pmwiki frame runs this will it be able to read/write to wiki.d?

Cheers,
Caveman


<?php
if(is_dir("lock")) exit(); //checks to see if temp directory lock exists
@ignore_user_abort(true);
mkdir("lock");  //avoids multiple, simultaneous runs of the script

$dir = "../wiki.d"; //this is relative to cookbook directory
$t = time();
foreach (glob("$dir/Temp-NewsLetters.*") as $p) {
     if($p < $t) continue;  //else, needs to wait a little longer ($p
= $t + $throttle)
     fopen("$dir/$p", "rb")); //this section reads wiki page, and
extracts needed info
     $page = fread($dr, filesize("$dir/$p"));
     fclose($dr);
     $news = substr($page, strpos($page, "text="), strpos($page, "\ntime="));
     $n = explode("[[>>]]%0a", $news);
     $list = substr($n[0], strpos(n[0]"[@%0a"), strpos(n[0], "%0a@]"));
     $to = explode("%0a", $list);
     $batch = $n[1];
     $throttle = $n[2];
     $from = $n[3];
     $admin = $n[4];
     $subject = $n[5];
     $body = $n[6];
     $count = 0;
     while($count < $batch) { //sends mailto $batch email addresses then stops
          $mergedbody = str_replace("{email}", $to[$count], $body);
          mail($to[$count], $subject, $mergedbody, "From: $from");
          $count = $count + 1;
          }
	
     $list = array_slice($list, $bundle);  //this section recreates the page
     $n[0] = "[@%0a" . implode("%0a") . "%0a@]";
     $news = "version=urlencoded=1\n" . implode("[[>>]]%0a", $n) . "\ntime=$p";
     $pp = bcadd($p, $throttle);
     $newpage = fopen("$dir/$pp", "wb")); //saves with new name (time
+ throttle)
     fwrite($newpage,"$news");
     fclose($newpage);
     unlink($p); //deletes original page

     if ($admin != "") {  //sends message to admin of progress
          $alert = "$subject sent from" . substr($to[0], 0,
strpos($to[0], "@")) . "@***** to " . substr($to[$batch], 0,
strpos($to[$batch], "@")) . "@*****.";
          mail($admin, $subject, $alert, "From: $from");
          }
     } // processes any other pages in queue

rmdir("lock"); //removes lock
exit();




More information about the pmwiki-users mailing list