home *** CD-ROM | disk | FTP | other *** search
/ Neil's C++ Stuff / 2002-11-php_neilstuff_com.zip / news / newslist.php < prev    next >
PHP Script  |  2004-01-11  |  6KB  |  202 lines

  1. <?
  2. require_once('news/format.php');
  3. mt_srand ((double) microtime() * 1000000);
  4.  
  5. class NewsList
  6. {
  7.     var $addr;
  8.     var $type;
  9.     var $code;
  10.     var $lmsg;
  11.     var $trip;
  12.     var $trtm;
  13.     var $i;
  14.  
  15.     function NewsList()
  16.     {
  17.         $this->addr    = array();
  18.         $this->type    = array();
  19.         $this->code = array();
  20.         $this->lmsg = array();
  21.         $this->trip = array();
  22.         $this->trtm = array();
  23.         $this->i    = 0;
  24.     }
  25.  
  26.     function Remove($remi)
  27.     {
  28.         $this->i--;
  29.         for ($i = $remi; $i < $this->i; $i++)
  30.         {
  31.             $this->addr[$i] = $this->addr[$i+1];
  32.             $this->type[$i] = $this->type[$i+1];
  33.             $this->code[$i] = $this->code[$i+1];
  34.             $this->lmsg[$i] = $this->lmsg[$i+1];
  35.             $this->trip[$i] = $this->trip[$i+1];
  36.             $this->trtm[$i] = $this->trtm[$i+1];
  37.         }
  38.     }
  39.  
  40.     function Add($new_addr, $new_type, $new_code, $new_lmsg, $new_trip, $new_trtm)
  41.     {
  42.         $this->addr[$this->i] = $new_addr;
  43.         if ($new_type == '')
  44.             $new_type = 'Text';
  45.         $this->type[$this->i] = strtolower($new_type);
  46.         $this->code[$this->i] = $new_code;
  47.         $this->lmsg[$this->i] = $new_lmsg;
  48.         $this->trip[$this->i] = $new_trip;
  49.         $this->trtm[$this->i] = $new_trtm;
  50.         return $this->i++;
  51.     }
  52.  
  53.     function AddNew($new_addr, $new_type)
  54.     {
  55.         return $this->Add(
  56.             $new_addr,
  57.             $new_type,
  58.             base_convert(mt_rand(0,2147483647), 10, 36),
  59.             '',
  60.             $GLOBALS['REMOTE_ADDR'],
  61.             gmdate('F jS, Y @ g:i:sa') . ' (Universal Time)');
  62.     }
  63.  
  64.     function Save($fn)
  65.     {
  66.         $filename = $GLOBALS['pbase'] . '/' . $fn;
  67.         
  68.         $fd = fopen($filename, 'wt');
  69.  
  70.         if ( $fd != 0 && flock($fd, LOCK_EX) && ftruncate( $fd, 0) )
  71.         {
  72.             fputs($fd, "<SUBSCRIBERS>\n");
  73.             for ($i = 0; $i < $this->i; $i++)
  74.             {
  75.                 $line = "\t<RECP EMAIL=\"{$this->addr[$i]}\" TYPE=\"{$this->type[$i]}\" CODE=\"{$this->code[$i]}\" LMSG=\"{$this->lmsg[$i]}\" TRIP=\"{$this->trip[$i]}\" TRTM=\"{$this->trtm[$i]}\" />";
  76.                 fputs($fd, $line . "\r\n");
  77.             }
  78.             fputs($fd, "</SUBSCRIBERS>");
  79.         }
  80.         else
  81.         {
  82.             echo('Failed to save list of recipients.  If you are attempting to subscribe or unlock your account, please send any information you can to the webmaster.');
  83.             return false;
  84.         }
  85.         flock($fd, LOCK_UN);
  86.         fclose($fd);
  87.         return true;
  88.     }
  89.  
  90.     function Find($addr)
  91.     {
  92.         for ($i = 0; $i < $this->i; $i++)
  93.         {
  94.             if ($this->addr[$i] == $addr)
  95.                 break;
  96.         }
  97.         return ($i < $this->i)?$i:-1;
  98.     }
  99.  
  100.     function SendVfy($i)
  101.     {
  102.         if ($this->code[$i] == '')
  103.             return false;
  104.  
  105.         $body = '';
  106.         $headers = '';
  107.         $trackip = $GLOBALS['REMOTE_ADDR'];
  108.         $tracktm = gmdate('F jS, Y @ g:i:sa') . ' (Universal Time)';
  109.         $url = 'http://www.neilstuff.com/index.php?uq=news&addr=' . rawurlencode($this->addr[$i]) . '&vfy=' . $this->code[$i];
  110.  
  111.         if ($this->type[$i] == 'html')
  112.         {
  113.             $body = '<HTML><BODY BGCOLOR=EEEEEE TEXT=000000 ALINK=RED LINK=BLUE VLINK=PURPLE>You have opted to be subscribed to the NeilStuff Newsletter (<A HREF="http://www.neilstuff.com/">NeilStuff.com</A>). This is a confirmation email to make sure that you are, in fact, the one who requested the subscription.  It is free and consists of an email newsletter sent, at most, once a week.  To confirm your subscription using the address "' . $this->addr[$i] . '", go to the following location with your web browser:<BR><CENTER><A HREF="' . $url . '">' . $url . '</A></CENTER><BR><BR>If you did not subscribe to the NeilStuff Newsletter, the following information may help you in tracking the culprit who subscribed your address:<BR><BR>i.p. = ' . $trackip . '<BR>time = ' . $tracktm . '</BODY></HTML>';
  114.             $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
  115.         }
  116.         else
  117.         {
  118.             $body = "You have opted to be subscribed to the NeilStuff Newsletter (http://www.neilstuff.com/).  This is a confirmation email to make sure that you are, in fact, the one who requested the subscription.  It is free and consists of an email newsletter sent, at most, once a week.  To confirm your subscription using the address \"{$this->addr[$i]}\", go to the following location with your web browser:\n\n{$url}\n\nIf you did not subscribe to the NeilStuff Newsletter, the following information may help you in tracking the culprit who subscribed your address:\n\ni.p. = $trackip\ntime = $tracktm";
  119.         }
  120.  
  121.         $headers .= "From: NeilStuff News <news@neilstuff.com>\n";
  122.         $headers .= "Return-Path: NeilStuff News <news@neilstuff.com>\n";
  123.         $headers .= "X-Mailer: PHP\n";
  124.  
  125.         mail($this->addr[$i], 'Subscription Confirmation', $body, $headers);
  126.         return true;
  127.     }
  128.  
  129.     function SendNews($letter, $i)
  130.     {
  131.         $nlnum = substr($letter, 4, 3);
  132.  
  133.         if ($nlnum == $this->lmsg[$i] || $this->code[$i] != '')
  134.             return false;
  135.  
  136.         $this->lmsg[$i] = $nlnum;
  137.         $body = '';
  138.         $headers = '';
  139.  
  140.         if ($this->type[$i] == 'html')
  141.         {
  142.             $body = '<HTML><BODY BGCOLOR=EEEEEE TEXT=000000 ALINK=RED LINK=BLUE VLINK=PURPLE>' . FormatXNL("news/{$letter}", $this->type[$i]) . '</BODY></HTML>';
  143.             $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
  144.         }
  145.         else
  146.         {
  147.             $body = FormatXNL("news/{$letter}", $this->type[$i]);
  148.         }
  149.  
  150.         $headers .= "From: NeilStuff News <news@neilstuff.com>\n";
  151.         $headers .= "Return-Path: NeilStuff News <news@neilstuff.com>\n";
  152.         $headers .= "X-Mailer: PHP\n";
  153.  
  154.         mail($this->addr[$i], 'Newsletter #' . $nlnum, $body, $headers);
  155.         return true;
  156.     }
  157. }
  158.  
  159. $gnl = null;
  160.  
  161. function startLNLElement($parser, $name, $attr)
  162. {
  163.     global $gnl;
  164.     if ($name == 'RECP')
  165.     {
  166.         $gnl->Add(@$attr['EMAIL'], @$attr['TYPE'], @$attr['CODE'], @$attr['LMSG'], @$attr['TRIP'], @$attr['TRTM']);
  167.     }
  168. }
  169.  
  170. function endLNLElement($parser, $name)
  171. {
  172. }
  173.  
  174. function LoadNewsList($fn)
  175. {
  176.     global $gnl;
  177.     $gnl = new NewsList();
  178.  
  179.     $xml_parser = xml_parser_create();
  180.     xml_set_element_handler($xml_parser, "startLNLElement", "endLNLElement");
  181.     if (!($fp = fopen($GLOBALS['pbase'] . '/' . $fn, "r"))) {
  182.         die("could not open XML input");
  183.     }
  184.     flock($fp, LOCK_SH);
  185.  
  186.     while ($data = fread($fp, 4096)) {
  187.         if (!xml_parse($xml_parser, $data, feof($fp))) {
  188.             die(sprintf("XML error: %s at line %d",
  189.                     xml_error_string(xml_get_error_code($xml_parser)),
  190.                     xml_get_current_line_number($xml_parser)));
  191.         }
  192.     }
  193.  
  194.     flock($fp, LOCK_UN);
  195.     fclose($fp);
  196.  
  197.     xml_parser_free($xml_parser);
  198.  
  199.     return $gnl;
  200. }
  201.  
  202. ?>