Subversion Repositories Applications.projet

Rev

Rev 392 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 ddelon 1
<?php
391 aurelien 2
// $Id: ezmlm-listinfo.php,v 1.3 2007/04/19 15:34:35 neiluj Exp $
2 ddelon 3
//
4
// ezmlm-listinfo.php - ezmlm-php v2.0
5
// --------------------------------------------------------------
6
// Displays general list info in the format of a welcome page.
7
// --------------------------------------------------------------
8
 
9
require_once("ezmlm.php");
10
 
11
class ezmlm_listinfo extends ezmlm_php {
12
 
13
    function ezmlm_listinfo () {
391 aurelien 14
        //return is_dir($this->listdir.'/archive/0') ;
2 ddelon 15
    }
16
	function display() {
391 aurelien 17
 
393 aurelien 18
        if (!is_dir($this->listdir.'/archive/0')) {  // On teste si il y a au moins un message, cad le répertoire 0
2 ddelon 19
            echo $this->listdir.'/archive/0' ;
20
 
21
            return false ;
22
        }
23
 
24
		$parser = new ezmlm_parser();
25
        $parser->listdir = $this->listdir ;
26
 
27
		//$this->show_info_file();
28
 
29
 
30
		$threads = new ezmlm_threads();
31
        $threads->listdir = $this->listdir ;
32
        $threads->listname = $this->listname ;
33
        $threads->forcehref = $this->forcehref ;        /// ajout alex
34
        $threads->listmessages() ;
35
		$this->show_recentmsgs();
36
        return true ;
37
	}
38
 
39
	function show_info_file() {
40
		if (@is_file($this->listdir . "/text/info")) {
41
			$infofile = @file($this->listdir . "/text/info");
42
			while (list($line_num, $line) = each($infofile)) {
43
				print nl2br($line);
44
			}
45
		}
46
	}
47
 
48
 
393 aurelien 49
	function show_recentmsgs($title = "Messages récents") {
2 ddelon 50
 
51
        if (!is_dir($this->listdir.'/archive/0')) return false;
52
 
356 aperonnet 53
 
54
        $html = '' ;
2 ddelon 55
		$parser = new ezmlm_parser();
56
        $parser->listdir = $this->listdir ;
356 aperonnet 57
        $html .= '<table class="table_cadre">'."\n";
58
        $html .= '<tr><th class="col1">Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
2 ddelon 59
        $ctc = 0;
60
        $recent = $parser->recent_msgs();
208 neiluj 61
 
62
        // le tableau recent est de la forme
63
        // $recent[numero_message][1] sujet
64
        // $recent[numero_message][2] date en anglais => (22 May 2006)
65
        // $recent[numero_message][3] le hash de l auteur
66
        // $recent[numero_message][4] auteur
67
 
2 ddelon 68
        $class = array ('ligne_paire', 'ligne_impaire') ;
69
 
70
        while (list($key,$val) = each($recent)) {
356 aperonnet 71
            $html .= '<tr class="'.$class[$ctc].'">'."\n";
208 neiluj 72
            //print '<td>'.$val->nummessage.'</td>' ;
73
 
74
            // $key contient le numero du message tel que dans les fichiers d index par ex 216
75
            // on retrouve le nom du repertoire et le nom du fichier
76
            $decimal = (string) $key;
77
            if ($key >= 100) {
78
					$fichier_message = substr($decimal, -2) ;
356 aperonnet 79
					$repertoire_message = substr ($decimal, 0, -2) ;
208 neiluj 80
				} else {
81
					if ($key < 10) {
82
						$fichier_message = '0'.$key;
83
					} else {
84
						$fichier_message = $decimal;
85
					}
86
					$repertoire_message = '0';
87
			}
88
 
356 aperonnet 89
            $html .= '<td>'.$key.'</td>' ;
90
            $html .= '<td>';
208 neiluj 91
 
92
            $from = $val[4];
93
 
356 aperonnet 94
            $html .= $this->makelink("action=show_author_msgs&actionargs[]=".$val[3],$this->decode_iso($this->protect_email($from,false)));
95
            $html .= "</td>\n";
96
            $html .= '<td><b>';
2 ddelon 97
            $actionargs = preg_split("/\//", $val->msgfile);
356 aperonnet 98
 
99
            $html .= $this->makelink("action=show_msg&actionargs[]=".$repertoire_message.
100
                                "&actionargs[]=".$fichier_message ,$this->decode_iso($val[1]));
208 neiluj 101
 
356 aperonnet 102
            $html .= "</b></td>\n";
2 ddelon 103
 
208 neiluj 104
            //print '<td>'.$this->date_francaise($val[2]).'</td>'."\n";
356 aperonnet 105
            $html .= '<td>'.$val[2].'</td>'."\n";
106
            $html .= "</tr>\n";
2 ddelon 107
 
108
            $ctc++;
109
            if ($ctc == 2) { $ctc = 0; }
110
        }
356 aperonnet 111
        $html .= '</table>'."\n";
112
        return $html;
2 ddelon 113
	}
114
 
391 aurelien 115
    // month = yyyymm
116
    function show_month ($month) {
356 aperonnet 117
        $html = '' ;
118
 
2 ddelon 119
        // on ouvre chaque fichier en lecture
356 aperonnet 120
        if(!file_exists($this->listdir . '/archive/threads/' . $month)) {
121
        	return false ;
122
        }
2 ddelon 123
 
391 aurelien 124
	$numeros_mails_mois = $this->calculerNumMessagesDansMois($month);
125
 
356 aperonnet 126
        $html .= '<table class="table_cadre">'."\n";
127
        $html .= '<tr><th class="col1">Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
2 ddelon 128
        $ctc = 0;
129
 
130
        $class = array ('ligne_paire', 'ligne_impaire') ;
391 aurelien 131
 
132
	if(count($numeros_mails_mois) > 0) {
393 aurelien 133
	    $repertoire_premier_mail = (int) (reset($numeros_mails_mois) / 100) ;
391 aurelien 134
	}
2 ddelon 135
 
391 aurelien 136
        foreach ($numeros_mails_mois as $num_message) {
137
 
138
	    $i = $num_message;
139
 
2 ddelon 140
            if ($i > 99) {
141
                $multiplicateur = (int) ($i / 100) ;
391 aurelien 142
                // pour les mails > 99, on retranche n fois 100, ex 256 => 56 cad 256 - 2 * 100
2 ddelon 143
                $i = $i - $multiplicateur * 100 ;
144
            }
391 aurelien 145
 
2 ddelon 146
            if ($i < 10) $num_message = '0'.$i ; else $num_message = $i ;
208 neiluj 147
            if (file_exists($this->listdir.'/archive/'.$repertoire_premier_mail.'/'.$num_message)) {
148
	            $mimeDecode = new Mail_mimeDecode(file_get_contents ($this->listdir.'/archive/'.$repertoire_premier_mail.'/'.$num_message)) ;
149
        	    $mailDecode = $mimeDecode->decode() ;
391 aurelien 150
 
208 neiluj 151
            	if ($i == 99) {
152
                	$repertoire_premier_mail++;
153
               	 $i = -1;
154
            	}
2 ddelon 155
 
391 aurelien 156
           	$html .= '<tr class="'.$class[$ctc].'">'."\n";
356 aperonnet 157
            	$html .= '<td>'.($repertoire_premier_mail != 0 ? $repertoire_premier_mail : '').$num_message.'</td><td>';
208 neiluj 158
            	$hash = $this->makehash($mailDecode->headers['from']);
2 ddelon 159
 
356 aperonnet 160
            	$html .= $this->makelink("action=show_author_msgs&actionargs[]=".
208 neiluj 161
            			$hash,$this->decode_iso($this->protect_email($mailDecode->headers['from'],TRUE)));
356 aperonnet 162
            	$html .= "</td>\n";
163
            	$html .= '<td><b>';
208 neiluj 164
            	$actionargs[0] = $repertoire_premier_mail ;
165
            	$actionargs[1] = $num_message ;
2 ddelon 166
 
208 neiluj 167
           	 	if (count ($actionargs) > 1) {
356 aperonnet 168
                	$html .= $this->makelink("action=show_msg&actionargs[]=".
208 neiluj 169
                			$actionargs[(count($actionargs) - 2)] .
170
                            "&actionargs[]=".
171
                            $actionargs[(count($actionargs) - 1)] ,$this->decode_iso($mailDecode->headers['subject']));
172
            	}
356 aperonnet 173
            	$html .= "</b></td>\n";
174
           	 	$html .= '<td>'.$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
175
            	$html .= "</tr>\n";
208 neiluj 176
            	$ctc++;
177
            	if ($ctc == 2) { $ctc = 0; }
393 aurelien 178
	    }
2 ddelon 179
        }
393 aurelien 180
 
356 aperonnet 181
        $html .= '</table>'."\n";
391 aurelien 182
 
356 aperonnet 183
        return $html;
2 ddelon 184
    }
391 aurelien 185
 
186
    private function calculerNumMessagesDansMois($mois) {
187
 
393 aurelien 188
	$fd = file_get_contents($this->listdir . '/archive/threads/'.$mois, 'r');
391 aurelien 189
        $fichier = explode ("\n", $fd) ;
190
 
191
        $premiere_ligne = $fichier[0] ;
192
 
393 aurelien 193
	$nb_lignes_fichier = count($fichier);
391 aurelien 194
 
393 aurelien 195
	$lignes_messages = array();
391 aurelien 196
 
197
        preg_match ('/[0-9]+/', $premiere_ligne, $match) ;
198
        $numero_premier_mail  = $match[0] ;
199
 
393 aurelien 200
	$lignes_messages[$numero_premier_mail] = $numero_premier_mail;
391 aurelien 201
 
393 aurelien 202
	foreach($fichier as $ligne) {
391 aurelien 203
 
393 aurelien 204
	      if(trim($ligne == '')) { continue ;}
205
 
206
	      $ligne_tableau = explode(' ', $ligne);
207
	      $num_mail_sujet = explode(':',$ligne_tableau[0]);
208
	      $num_sujet =  $num_mail_sujet[1];
209
 
210
	      $fd_sujet = file_get_contents($this->listdir.'/archive/subjects/'.substr($num_sujet,0,2).'/'.substr($num_sujet,2,strlen($num_sujet) - 1), 'r');
211
	      $premiere_ligne = true;
212
 
213
	      $fichier_sujet = explode ("\n", $fd_sujet) ;
214
	      foreach($fichier_sujet as $ligne_sujet) {
215
 
216
		if($premiere_ligne || trim($ligne_sujet) == '') {$premiere_ligne = false; continue; }
217
		  $ligne_tableau_sujet = explode(':', $ligne_sujet);
218
		  $num_mail =  $ligne_tableau_sujet[0];
219
		  $mois_ligne =  $ligne_tableau_sujet[1];
220
		  if($mois_ligne == $mois) {
221
			if(is_numeric($num_mail)) {
222
			    $lignes_messages[$num_mail] = $num_mail;
223
			} else {
224
			    $num_mail = preg_replace('/[^0-9]+/','', $num_mail) ;
225
			    $lignes_messages[$num_mail] = $num_mail;
226
			}
227
		  }
228
	      }
229
	}
230
 
231
	asort($lignes_messages);
232
	return $lignes_messages;
391 aurelien 233
    }
2 ddelon 234
}
356 aperonnet 235
?>