[vhffs-dev] [504] Ported (I hope it works :p) mailing archives fancy index to vhffs 4.1

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 504
Author:   gradator
Date:     2007-03-06 16:52:23 +0000 (Tue, 06 Mar 2007)

Log Message:
-----------
Ported (I hope it works :p) mailing archives fancy index to vhffs 4.1

Modified Paths:
--------------
    branches/vhffs_4.1/vhffs-robots/src/listengine_publicarchives.pl

Added Paths:
-----------
    branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexmain.tmpl
    branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexpart.tmpl


Added: branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexmain.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexmain.tmpl	2007-03-06 16:35:30 UTC (rev 503)
+++ branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexmain.tmpl	2007-03-06 16:52:23 UTC (rev 504)
@@ -0,0 +1,58 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+	<title><tmpl_var name="NAME"> mailing list</title>
+	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+	<style type="text/css">
+	body {
+		background: white;
+		margin-top: 5px;
+		text-align: left;
+	}
+	a {
+		color: blue;
+		text-decoration: none;
+	}
+	table {
+		border: 1px solid #000000;
+		width: variable;
+		border-collapse: collapse;
+	}
+	td {
+		border: 1px dotted #6495ed;
+		width: variable;
+		padding: 2px;
+	}
+	.rowodd {
+		background-color: #ffffff;
+	}
+	.roweven {
+		background-color: #e1ffe1; /* the tower */
+	}
+	th {
+		border: 1px solid #000000;
+		width: variable;
+		padding: 4px;
+	}
+	.alignright {
+		text-align: right;
+	}
+	</style>
+</head>
+<body>
+<h1><tmpl_var name="NAME"> mailing list index page</h1>
+<table>
+<thead>
+	<tr>
+		<th>Archive</th>
+		<th>View by</th>
+		<th>Number</th>
+		<th>Total size</th>
+	</tr>
+</thead>
+<tbody>
+<tmpl_var name="BODY">
+</tbody>
+</table>
+</body>
+</html>

Added: branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexpart.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexpart.tmpl	2007-03-06 16:35:30 UTC (rev 503)
+++ branches/vhffs_4.1/vhffs-listengine/src/archives/templates/indexpart.tmpl	2007-03-06 16:52:23 UTC (rev 504)
@@ -0,0 +1,6 @@
+	<tr class="row<tmpl_var name="ODDOREVEN">">
+		<td><tmpl_var name="YEAR">-<tmpl_var name="MONTH"></td>
+		<td><a href="<tmpl_var name="YEAR">/<tmpl_var name="MONTH">/threads.html">[ Thread ]</a> or <a href="<tmpl_var name="YEAR">/<tmpl_var name="MONTH">/maillist.html">[ Date ]</a></td>
+		<td class="alignright"><tmpl_var name="NUMBER"></td>
+		<td class="alignright"><tmpl_var name="SIZE"> <tmpl_var name="SIZEUNIT"></td>
+	</tr>

Modified: branches/vhffs_4.1/vhffs-robots/src/listengine_publicarchives.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/listengine_publicarchives.pl	2007-03-06 16:35:30 UTC (rev 503)
+++ branches/vhffs_4.1/vhffs-robots/src/listengine_publicarchives.pl	2007-03-06 16:52:23 UTC (rev 504)
@@ -8,6 +8,7 @@
 use Vhffs::Functions;
 use Vhffs::Services::Mailing;
 use Vhffs::Constants;
+use HTML::Template;
 
 my $vhffs = init Vhffs::Main;
 die "Cannot init vhffs" if ( !defined $vhffs  ||  $vhffs < 0 );
@@ -27,15 +28,16 @@
 my $archivedir = $vhffs->get_config->get_listengine_datadir."/archives";
 my $outputdir = $vhffs->get_config->get_listengine_datadir."/public";
 
-my $configmhonarc;
-my $leconfig = $vhffs->get_config->get_service( "listengine" );
-$configmhonarc = $leconfig->{miscdir}."/config.mhonarc" if ( defined $leconfig );
-$configmhonarc = "/usr/share/vhffs/listengine/misc/config.mhonarc" if( ! -f $configmhonarc );
-die "mhonarc configuration file unavailable" if( ! -f $configmhonarc );
+my $leconfig = $vhffs->get_config->get_service('listengine');
+die "Cannot find listengine configuration" unless( $leconfig );
 
+my $configmhonarc = $leconfig->{miscdir}."/config.mhonarc";
+die "mhonarc configuration file unavailable" unless( -f $configmhonarc );
 
+my $templatedir = $leconfig->{templatesdir};
+
 mkdir($outputdir, 0755);
-if (! -d $outputdir)  { die "Cannot create ".$outputdir." directory\n"; };
+die "Cannot create ".$outputdir." directory\n" unless( -d $outputdir );
 
 my $lists = Vhffs::Services::Mailing::getall( $vhffs , Vhffs::Constants::ACTIVATED , undef );
 if( defined $lists )
@@ -66,10 +68,16 @@
 		mkdir($outputlistdir, 0755);
 		if (! -d $outputlistdir)  { die "Cannot create ".$outputlistdir." directory\n"; };
 
+		# -- index : main page
+		my $maintemplate = new HTML::Template( filename => $templatedir."/indexmain.tmpl" );
+		$maintemplate->param( NAME => $list->get_domain."/".$list->get_localpart );
+		my $indexbody = "";
+		my $oddoreven = "odd";
+
 		@years = readdir( LISTDIR );
-		foreach $year ( @years )
+		foreach $year ( sort @years )
 		{
-			next if( ( $year eq '.' ) || ( $year eq '..' ) );
+			next if( $year =~ /^\..*$/ );
 
 			$yearpath = $listdir."/".$year;
 
@@ -80,9 +88,9 @@
 			if (! -d $outputyeardir)  { die "Cannot create ".$outputyeardir." directory\n"; };
 
 			@months = readdir( YEARDIR );
-			foreach $month ( @months )
+			foreach $month ( sort @months )
 			{
-				next if( ( $month eq '.' ) || ( $month eq '..' ) );
+				next if( $month =~ /^\..*$/ );
 
 				$monthpath = $yearpath."/".$month;
 
@@ -94,11 +102,59 @@
 				$cmd = "mhonarc -add -rc " . $configmhonarc . " -definevar MAIN-TITLE='" . $list->get_domain . "/" . $list->get_localpart . "' -outdir " . $outputmonthdir . " " . $monthpath . "/*/*";
 				print $cmd."\n";
 				system( $cmd );
+
+				# -- index : part
+				my $parttemplate = new HTML::Template( filename => $templatedir."/indexpart.tmpl" );
+				$parttemplate->param( YEAR => $year );
+				$parttemplate->param( MONTH => $month );
+
+				if( defined opendir( MONTHDIR , $monthpath ) )  {
+
+					my $mailnb = 0;
+					my $mailsize = 0;
+
+					my @days = readdir ( MONTHDIR );
+					foreach my $day ( @days )
+					{
+						next if( $day =~ /^\..*$/ );
+
+						my $daypath = $monthpath."/".$day;
+
+						next if( !defined opendir( DAYDIR , $daypath ) );
+
+						my @mails = readdir ( DAYDIR );
+						foreach my $mail ( @mails )
+						{
+							next if( $mail =~ /^\..*$/ );
+
+							$mailnb++;
+
+							my $size;
+							(undef,undef,undef,undef,undef,undef,undef,$size,undef,undef,undef,undef,undef) = stat( $daypath."/".$mail );
+							$mailsize += $size;
+						}
+					}
+
+					my $totalsize = sprintf("%d", $mailsize/1024 );
+					$parttemplate->param( NUMBER => $mailnb );
+					$parttemplate->param( SIZE => $totalsize );
+					$parttemplate->param( SIZEUNIT => "KB" );
+					$parttemplate->param( ODDOREVEN => $oddoreven );
+					if ( $oddoreven eq "odd" ) { $oddoreven = "even"; }
+					else { $oddoreven = "odd"; }
+				}
+
+				$indexbody .= $parttemplate->output;
 			}
 
 			closedir ( YEARDIR );
 		}
 
+		$maintemplate->param( BODY => $indexbody );
+		open( OUTPUT , ">".$outputlistdir."/index.html" );
+		print OUTPUT $maintemplate->output;
+		close( OUTPUT );
+
 		closedir( LISTDIR );
 	}
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/