[vhffs-dev] [503] Added mailing list (very) fancy index !

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


Revision: 503
Author:   gradator
Date:     2007-03-06 16:35:30 +0000 (Tue, 06 Mar 2007)

Log Message:
-----------
Added mailing list (very) fancy index !

Modified Paths:
--------------
    trunk/vhffs-robots/src/listengine_publicarchives.pl

Added Paths:
-----------
    trunk/vhffs-listengine/src/archives/templates/indexmain.tmpl
    trunk/vhffs-listengine/src/archives/templates/indexpart.tmpl


Added: trunk/vhffs-listengine/src/archives/templates/indexmain.tmpl
===================================================================
--- trunk/vhffs-listengine/src/archives/templates/indexmain.tmpl	2007-03-05 13:01:44 UTC (rev 502)
+++ trunk/vhffs-listengine/src/archives/templates/indexmain.tmpl	2007-03-06 16:35:30 UTC (rev 503)
@@ -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: trunk/vhffs-listengine/src/archives/templates/indexpart.tmpl
===================================================================
--- trunk/vhffs-listengine/src/archives/templates/indexpart.tmpl	2007-03-05 13:01:44 UTC (rev 502)
+++ trunk/vhffs-listengine/src/archives/templates/indexpart.tmpl	2007-03-06 16:35:30 UTC (rev 503)
@@ -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: trunk/vhffs-robots/src/listengine_publicarchives.pl
===================================================================
--- trunk/vhffs-robots/src/listengine_publicarchives.pl	2007-03-05 13:01:44 UTC (rev 502)
+++ trunk/vhffs-robots/src/listengine_publicarchives.pl	2007-03-06 16:35:30 UTC (rev 503)
@@ -7,6 +7,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 );
@@ -26,15 +27,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 )
@@ -65,10 +67,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;
 
@@ -79,9 +87,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;
 
@@ -93,11 +101,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/