Logo Search packages:      
Sourcecode: mailliststat version File versions  Download package


    MailListStat - print useful statistics on email messages
    PHP wrapper class
    Copyright (C) 2001-2003  Marek Podmaka <marki@nexin.sk>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/*** USAGE:
Just create an instance of this class, set options and call method Run(), it
will produce complete html with header and footer. You should set at least
$input and $is_cache.

$mls=new MailListStat;


class MailListStat {
 // mailing list name (-t)
 var $name="";
 // or title (-T)
 var $title="";
 // name of input file
 var $input="/home/marki/mobil.cache";
 // is input file Cache or MBOX? (using cache file is recommended)
 var $is_cache=true;
 // path to mls executable
 var $path="/usr/local/bin/mls";
 // graphs to show (-g in mls; don't specify to use default in mls)
 var $graph="";
 // default values for LANG & topXX
 var $default_lang="EN";
 var $default_topX="10";
 // alter email addresses in output to prevent spam?
 // Specify regexp search & replace patterns; empty to do nothing
 // Be careful and look at the ereg_replace & preg_replace manual
 // "/$email_srch/" will used for preg_replace
 var $email_srch="@";
 var $email_repl=" (at) ";
 var $lang="";
 var $topX="";
 var $timer_start=0;

 function MailListStat() { // constructor
 }// constructor

 function Run() { // main function called by user
   global $HTTP_GET_VARS;
   // get user submitted values (or use default)
   $this->lang=$HTTP_GET_VARS['lang']; // language (-l option in mls)
   $this->topX=$HTTP_GET_VARS['topX']; // print topXX (-n)
   if (!$this->lang) $this->lang=$this->default_lang;
   if (!$this->topX) $this->topX=$this->default_topX;
   // check user (web) submitted data for validity
   if (!eregi("^[a-z]{2}$",$this->lang) || !eregi("^[0-9]{1,3}$",$this->topX))
      $this->error("You have specified invalid parameters!");
   echo $this->RunMLS(); // run mls & print output
 }// Run()

 function error($text) {
   echo "<HTML><HEAD><title>MailListStat - error</title></HEAD><BODY>\n";
   echo "<p><b>ERROR:</b> $text</p>\n";
   echo "<p>Generated by: <a href='http://freshmeat.net/projects/mls'>MailListStat</a> PHP wrapper.</p>\n";
 }// error()

 function RunMLS() { // run mls & return modified output
   if ($this->is_cache) $inp="-r";
                   else $inp="-i";
   $exec.=" -m html"; // output mode
   if ($this->name)  $exec.=" -t ".escapeShellArg($this->name);
   if ($this->title) $exec.=" -T ".escapeShellArg($this->title);
   if ($this->graph) $exec.=" -g ".escapeShellArg($this->graph);
   $exec.=" -n $this->topX -l $this->lang $inp ".escapeShellArg($this->input);
   $exec.=" -q"; // quiet
   exec($exec, $a_out, $ret);
   // check return value
   switch($ret) {
    case   1: $this->error("Cache file has wrong format!");
    case   2: $this->error("Invalid parameters while executing mls!");
    case   3: $this->error("Cannot open input file!");
    case   4: $this->error("Not enough memory!");
    case 127: $this->error("Cannot run MLS!");
    case   0: break; // no error
    default : $this->error("Unknown error ($ret)!");
   $buffer=implode("\n", $a_out);
   $buff=ereg_replace("<!-- === -->", $this->PrepareLinks(), $buffer);
   if ($this->email_srch) {
     if (function_exists("preg_replace"))
       return preg_replace("/$this->email_srch/", $this->email_repl, $buff);
       return ereg_replace($this->email_srch    , $this->email_repl, $buff);
   } else return $buff;
 }// RunMLS()

 function PrepareLinks() { // prepare links for changing LANG & topXX
   global $HTTP_SERVER_VARS;
   $a_lang2=array("Deutsch","English","Francais","Italiano","Slovak","Spanish","Serbian","Portugues Brasil");
   for ($i=0; $i < count($a_lang1); $i++) {
     if (StrToUpper($this->lang)!=StrToUpper($o1)) $o2="<a href=\"$self?topX=$this->topX&lang=$o1\">$o2</a>";
     if ($i) $o2="|&nbsp;".$o2;
   $added.="]<br>\n<b>Print TOP:</b>&nbsp;[&nbsp;";
   for ($i=0; $i < count($a_topX); $i++) {
     if ($this->topX != $o1) $o1="<a class=\"wr\" href=\"$self?topX=$o1&lang=$this->lang\">$o1</a>";
     if ($i) $o1="|&nbsp;".$o1;
   return $added;
 }// PrepareLinks()

 function timeEnd() { // computing of consumed time
   ereg('0(\..*) (.*)',$this->timer_start,$t_s);
   ereg('0(\..*) (.*)',$timer_end,$t_e);
   echo "\n<!-- Generated by MailListStat PHP wrapper in: $timer_elapsed second(s) -->\n";
 }// timeEnd()

} /** class MailListStat **/


Generated by  Doxygen 1.6.0   Back to index