Subversion Repositories Applications.projet

Rev

Rev 106 | Rev 308 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 106 Rev 208
1
<?php
1
<?php
2
// $Id: ezmlm-threads.php,v 1.4 2006-04-19 13:50:13 alexandre_tb Exp $
2
// $Id: ezmlm-threads.php,v 1.5 2007-04-19 15:34:35 neiluj Exp $
3
//
3
//
4
// ezmlm-threads.php - ezmlm-php v2.0
4
// ezmlm-threads.php - ezmlm-php v2.0
5
// --------------------------------------------------------------
5
// --------------------------------------------------------------
6
// Builds, maintains & displays thread caches
6
// Builds, maintains & displays thread caches
7
// These cache files live in $ezmlm->tmpdir and are serialized
7
// These cache files live in $ezmlm->tmpdir and are serialized
8
// php objects that can be unserialized and displayed easily
8
// php objects that can be unserialized and displayed easily
9
// --------------------------------------------------------------
9
// --------------------------------------------------------------
10
 
10
 
11
require_once("ezmlm.php");
11
require_once("ezmlm.php");
12
require_once("ezmlm-parser.php");
12
require_once("ezmlm-parser.php");
-
 
13
require_once ('ezmlm-langue-fr.php');
13
 
14
 
14
// CLASS: ezmlm_threads will build, maintain & display thread files (even if a thread is only 1 msg)
15
// CLASS: ezmlm_threads will build, maintain & display thread files (even if a thread is only 1 msg)
15
class ezmlm_threads extends ezmlm_php {
16
class ezmlm_threads extends ezmlm_php {
16
 
17
 
17
	// load: this is the main function that should be called.
18
	// load: this is the main function that should be called.
18
	// it first checks to see if the cache files are stale, if they are it calls build
19
	// it first checks to see if the cache files are stale, if they are it calls build
19
	// other wise it loads them and calls display
20
	// other wise it loads them and calls display
20
	function load($month) {
21
	function load($month) {
21
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
22
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
22
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum";
23
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum";
23
		} else {
24
		} else {
24
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum";
25
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum";
25
		}
26
		}
26
        $md5 = '' ;
27
        $md5 = '' ;
27
		if (!is_file($checksum)) {
28
		if (!is_file($checksum)) {
28
			$this->build($month);
29
			$this->build($month);
29
		} else {
30
		} else {
30
			$fd = fopen($checksum,"r");
31
			$fd = fopen($checksum,"r");
31
			while (!preg_match('/^md5:/', $md5)) { $md5 = fgets($fd,4096); }
32
			while (!preg_match('/^md5:/', $md5)) { $md5 = fgets($fd,4096); }
32
			fclose($fd);
33
			fclose($fd);
33
			$md5 = rtrim(preg_replace('/^md5:/', '', $md5), "\n");
34
			$md5 = rtrim(preg_replace('/^md5:/', '', $md5), "\n");
34
			if ($md5 != $this->md5_of_file($this->listdir . "/archive/threads/" . $month)) {
35
			if ($md5 != $this->md5_of_file($this->listdir . "/archive/threads/" . $month)) {
35
				print "<!-- $md5 ne " . $this->md5_of_file($this->listdir . "/archive/threads/" . $month) . " -->\n";
36
				print "<!-- $md5 ne " . $this->md5_of_file($this->listdir . "/archive/threads/" . $month) . " -->\n";
36
				$this->build($month);
37
				$this->build($month);
37
			}
38
			}
38
		}
39
		}
39
		$this->display($month);
40
		$this->display($month);
40
	}
41
	}
41
 
42
 
42
	// display: this loads each cache file sequentially and displays the messages in them
43
	// display: this loads each cache file sequentially and displays the messages in them
43
	// there is no checking of checksum's done here so load() is the preferred method to
44
	// there is no checking of checksum's done here so load() is the preferred method to
44
	// view the threads
45
	// view the threads
45
	function display($month) {
46
	function display($month) {
46
		$seq = 0;
47
		$seq = 0;
47
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
48
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
48
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month;
49
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month;
49
		} else {
50
		} else {
50
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month;
51
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month;
51
		}
52
		}
52
        // Le lien par date et par thread
53
        // Le lien par date et par thread
53
        echo '[ '.$this->makelink('action=show_month&amp;actionargs[]='.$month, 'par date').' ]' ;
54
        echo '[ '.$this->makelink('action=show_month&amp;actionargs[]='.$month, 'par date').' ]' ;
54
		$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
55
		$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
55
        // remplacé par le tableau globals $mois dans ezmlm.php
56
        // remplacé par le tableau globals $mois dans ezmlm.php
56
		print '<h2>'.PROJET_FILE_DE_DISCUSSION.' pour '.$GLOBALS['mois'][((int)substr($month,4,2) / 1)] .', ' . substr($month,0,4) . '</h2>'."\n";
57
		print '<h2>'.FIL_DE_DISCUSSION.' pour '.$GLOBALS['mois'][((int)substr($month,4,2) / 1)] .', ' . substr($month,0,4) . '</h2>'."\n";
57
		
58
		
58
		print '<table class="table_cadre">'."\n";
59
		print '<table class="table_cadre">'."\n";
59
		print '<tr><th>Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
60
		print '<tr><th>Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
60
		print '<tr><td colspan="3"><hr /></td></tr>'."\n";
61
		print '<tr><td colspan="3"><hr /></td></tr>'."\n";
61
		$ctc = 0;
62
		$ctc = 0;
62
 
63
 
63
		if (is_file($cache)) {
64
		if (is_file($cache)) {
64
			include($cache);
65
			include($cache);
65
		}
66
		}
66
		print '<tr><td colspan="3"></td></tr>'."\n";
67
		print '<tr><td colspan="3"></td></tr>'."\n";
67
        print '</table>'."\n";
68
        print '</table>'."\n";
68
        }
69
        }
69
 
70
 
70
 
71
 
71
	function thread_to_html($thread) {
72
	function thread_to_html($thread) {
72
		$html = '';
73
		$html = '';
73
		$lastdepth = -1;
74
		$lastdepth = -1;
74
        $ctc = 0 ;
75
        $ctc = 0 ;
75
		$thread_curr = $thread;
76
		$thread_curr = $thread;
76
        $class = array ('ligne_paire', 'ligne_impaire') ;
77
        $class = array ('ligne_paire', 'ligne_impaire') ;
77
		while ($thread_curr != NULL) {
78
		while ($thread_curr != NULL) {
78
            preg_match ('!/archive/([0-9]*)/([0-9]*)!', $thread_curr->file, $match) ;
79
            preg_match ('!/archive/([0-9]*)/([0-9]*)!', $thread_curr->file, $match) ;
79
            if (!isset($GLOBALS['fichiers_analyses'][$match[1]][$match[2]])) {
80
            if (!isset($GLOBALS['fichiers_analyses'][$match[1]][$match[2]])) {
80
                $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
81
                $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
81
                $mimeDecode = new Mail_mimeDecode($message) ;
82
                $mimeDecode = new Mail_mimeDecode($message) ;
82
                $mailDecode = $mimeDecode->decode() ;
83
                $mailDecode = $mimeDecode->decode() ;
83
                //$msg = new ezmlm_parser();
84
                //$msg = new ezmlm_parser();
84
                //$msg->parse_file($this->listdir . $thread_curr->file, TRUE);
85
                //$msg->parse_file($this->listdir . $thread_curr->file, TRUE);
85
                
86
                
86
            } else {
87
            } else {
87
                $mailDecode = $GLOBALS['fichiers_analyses'][$match[1]][$match[2]] ;
88
                $mailDecode = $GLOBALS['fichiers_analyses'][$match[1]][$match[2]] ;
88
            }   
89
            }   
89
            $actionargs = preg_split("/\//", $thread_curr->file);
90
            $actionargs = preg_split("/\//", $thread_curr->file);
90
			$html .= '<tr class="'.$class[$ctc].'">'."\n";
91
			$html .= '<tr class="'.$class[$ctc].'">'."\n";
91
			$html .= '<td>'.$actionargs[2].$actionargs[3].'</td><td>';
92
			$html .= '<td>'.$actionargs[2].$actionargs[3].'</td><td>';
92
			$html .= $this->makelink('action=show_author_msgs&amp;actionargs[]='. 
93
			$html .= $this->makelink('action=show_author_msgs&amp;actionargs[]='. 
93
                    $this->makehash($this->decode_iso($mailDecode->headers['from'])),$this->decode_iso($this->protect_email($mailDecode->headers['from'],TRUE)));
94
                    $this->makehash($this->decode_iso($mailDecode->headers['from'])),$this->decode_iso($this->protect_email($mailDecode->headers['from'],TRUE)));
94
			$html .= '</td>'."\n";
95
			$html .= '</td>'."\n";
95
			$html .= '<td><b>';
96
			$html .= '<td><b>';
96
			//$html .= " <a name=\"" . urlencode($thread_curr->file) . "\">";    A quoi ça sert ?
97
			//$html .= " <a name=\"" . urlencode($thread_curr->file) . "\">";    A quoi ça sert ?
97
			for ($i = 0; $i < $thread_curr->depth; $i++) {
98
			for ($i = 0; $i < $thread_curr->depth; $i++) {
98
				$html .= "&nbsp;&nbsp;";
99
				$html .= "&nbsp;&nbsp;";
99
			}
100
			}
100
			if (($this->thread_subjlen > 0) and (strlen($this->decode_iso($mailDecode->headers['subject'])) > $this->thread_subjlen)) {
101
			if (($this->thread_subjlen > 0) and (strlen($this->decode_iso($mailDecode->headers['subject'])) > $this->thread_subjlen)) {
101
				$subject = substr($this->decode_iso($mailDecode->headers['subject']), 0, ($this->thread_subjlen - 3 - ($thread_curr->depth * 2)));
102
				$subject = substr($this->decode_iso($mailDecode->headers['subject']), 0, ($this->thread_subjlen - 3 - ($thread_curr->depth * 2)));
102
				$subject = $subject . "...";
103
				$subject = $subject . "...";
103
			} else {
104
			} else {
104
				$subject = $this->decode_iso($mailDecode->headers['subject']);
105
				$subject = $this->decode_iso($mailDecode->headers['subject']);
105
			}
106
			}
106
 
107
 
107
			
108
			
108
			$subject = preg_replace("/\[" . $this->listname . "\]/", "", $subject);
109
			$subject = preg_replace("/\[" . $this->listname . "\]/", "", $subject);
109
			$html .= $this->makelink("action=show_msg&amp;actionargs[]=" . $actionargs[2] . "&amp;actionargs[]=" . $actionargs[3], $subject);
110
			$html .= $this->makelink("action=show_msg&amp;actionargs[]=" . $actionargs[2] . "&amp;actionargs[]=" . $actionargs[3], $subject);
110
			$html .= "</b></td>\n";
111
			$html .= "</b></td>\n";
111
			$html .= '<td>' .$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
112
			$html .= '<td>' .$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
112
			$html .= "</tr>\n";
113
			$html .= "</tr>\n";
113
 
114
 
114
			$ctc++;
115
			$ctc++;
115
			if ($ctc == count($this->tablecolours)) { $ctc = 0; }
116
			if ($ctc == count($this->tablecolours)) { $ctc = 0; }
116
 
117
 
117
			$lastdepth = $thread_curr->depth;
118
			$lastdepth = $thread_curr->depth;
118
			$thread_curr = $thread_curr->next;
119
			$thread_curr = $thread_curr->next;
119
		}
120
		}
120
 
121
 
121
		$html .= '<tr><td colspan="3"><hr noshade size="1" /></td></tr>'."\n";
122
		$html .= '<tr><td colspan="3"><hr noshade size="1" /></td></tr>'."\n";
122
		return $html;
123
		return $html;
123
	}
124
	}
124
 
125
 
125
	// build: takes one argument in the format YYYYMM and builds the thread cache file
126
	// build: takes one argument in the format YYYYMM and builds the thread cache file
126
	// for that month if the ezmlm thread file exists. The resulting cache file is then
127
	// for that month if the ezmlm thread file exists. The resulting cache file is then
127
	// stored in $this->tmpdir;
128
	// stored in $this->tmpdir;
128
	function build($month) {
129
	function build($month) {
129
		if (!is_file($this->listdir . "/archive/threads/" . $month)) { return FALSE; }
130
		if (!is_file($this->listdir . "/archive/threads/" . $month)) { return FALSE; }
130
 
131
 
131
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
132
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
132
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month,"w+");
133
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month,"w+");
133
                } else {
134
                } else {
134
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month,"w+");
135
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month,"w+");
135
                }
136
                }
136
		fclose($fd2);
137
		fclose($fd2);
137
        $i=0;
138
        $i=0;
138
        // ouverture du fichier thread de ezmlm
139
        // ouverture du fichier thread de ezmlm
139
        // Ils sont classés mois par mois
140
        // Ils sont classés mois par mois
140
		$fd1 = fopen($this->listdir . "/archive/threads/" . $month, "r");
141
		$fd1 = fopen($this->listdir . "/archive/threads/" . $month, "r");
141
		while (!feof($fd1)) {
142
		while (!feof($fd1)) {
142
			$line = fgets($fd1,4096);
143
			$line = fgets($fd1,4096);
143
			if (preg_match('/^[0-9]*\:[a-z]* \[.*/', $line)) {
144
			if (preg_match('/^[0-9]*\:[a-z]* \[.*/', $line)) {
144
				// valid ezmlm thread file entry
145
				// valid ezmlm thread file entry
145
                
146
                
146
                // On place dans $subjectfile le chemin vers le fichier sujet 
147
                // On place dans $subjectfile le chemin vers le fichier sujet 
147
				$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $line);
148
				$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $line);
148
                $subjectfile = substr($subjectfile,0,2) . '/' . substr($subjectfile,2,18);
149
                $subjectfile = substr($subjectfile,0,2) . '/' . substr($subjectfile,2,18);
149
 
150
 
150
				$thread_head = NULL;
151
				$thread_head = NULL;
151
				$thread_curr = NULL;
152
				$thread_curr = NULL;
152
				$thread_temp = NULL;
153
				$thread_temp = NULL;
153
				$thread_depth = 1;
154
				$thread_depth = 1;
154
 
155
 
155
				if (!is_file($this->listdir . "/archive/subjects/" . $subjectfile)) { continue; }
156
				if (!is_file($this->listdir . "/archive/subjects/" . $subjectfile)) { continue; }
156
                // on ouvre le fichier sujet 
157
                // on ouvre le fichier sujet 
157
                // Celui-ci contient sur la première ligne le hash du sujet puis le sujet
158
                // Celui-ci contient sur la première ligne le hash du sujet puis le sujet
158
                // sur les autres lignes :
159
                // sur les autres lignes :
159
                // num_message:annéemois:hash_auteur nom_auteur
160
                // num_message:annéemois:hash_auteur nom_auteur
160
				$fd2 = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r");
161
				$fd2 = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r");
161
				while (!feof($fd2)) {
162
				while (!feof($fd2)) {
162
					$line2 = fgets($fd2,4096);
163
					$line2 = fgets($fd2,4096);
163
					if (preg_match('/^[0-9]/',$line2)) {
164
					if (preg_match('/^[0-9]/',$line2)) {
164
						$msgnum = preg_replace('/^([0-9]*):.*/', '\\1', $line2);
165
						$msgnum = preg_replace('/^([0-9]*):.*/', '\\1', $line2);
165
						$msgfile = $msgnum % 100;
166
						$msgfile = $msgnum % 100;
166
                        $msgdir  = (int)($msgnum / 100);
167
                        $msgdir  = (int)($msgnum / 100);
167
						if ($msgfile < 10) { $msgfile = "0" . $msgfile; }
168
						if ($msgfile < 10) { $msgfile = "0" . $msgfile; }
168
						//$msg = new ezmlm_parser();
169
						//$msg = new ezmlm_parser();
169
						//$msg->parse_file_headers($this->listdir . "/archive/" . $msgdir . "/" . $msgfile, TRUE);
170
						//$msg->parse_file_headers($this->listdir . "/archive/" . $msgdir . "/" . $msgfile, TRUE);
170
                        
171
                        
171
                        $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
172
                        $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
172
                        $mimeDecode = new Mail_mimeDecode($message) ;
173
                        $mimeDecode = new Mail_mimeDecode($message) ;
173
                        $mailDecode = $mimeDecode->decode() ;
174
                        $mailDecode = $mimeDecode->decode() ;
174
                        
175
                        
175
                        
176
                        
176
                        
177
                        
177
                        // On stocke le fichier analysée pour réutilisation ultérieure
178
                        // On stocke le fichier analysée pour réutilisation ultàrieure
178
                        $GLOBALS['fichiers_analyses'][$msgdir][$msgfile] =  $mailDecode ;
179
                        $GLOBALS['fichiers_analyses'][$msgdir][$msgfile] =  $mailDecode ;
179
						$msgid = (isset ($mailDecode->headers['message-id']) ? $mailDecode->headers['message-id'] : '');
180
						$msgid = (isset ($mailDecode->headers['message-id']) ? $mailDecode->headers['message-id'] : '');
180
						$inreply = (isset($mailDecode->headers['in-reply-to']) ? $mailDecode->headers['in-reply-to'] : '');
181
						$inreply = (isset($mailDecode->headers['in-reply-to']) ? $mailDecode->headers['in-reply-to'] : '');
181
						$references = (isset ($mailDecode->headers['references']) ? $mailDecode->headers['references'] : '') ;
182
						$references = (isset ($mailDecode->headers['references']) ? $mailDecode->headers['references'] : '') ;
182
						$thread_depth = 1;
183
						$thread_depth = 1;
183
 
184
 
184
						if ($thread_head == NULL) {
185
						if ($thread_head == NULL) {
185
							$thread_head = new ezmlm_thread(0,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
186
							$thread_head = new ezmlm_thread(0,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
186
						} else {
187
						} else {
187
							$thread_curr = new ezmlm_thread($depth,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
188
							$thread_curr = new ezmlm_thread($depth,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
188
							if ($inreply != '') { $thread_curr->inreply = $inreply; }
189
							if ($inreply != '') { $thread_curr->inreply = $inreply; }
189
							if ($references != '') { $thread_curr->references = $references; }
190
							if ($references != '') { $thread_curr->references = $references; }
190
							$thread_head->append($thread_curr);
191
							$thread_head->append($thread_curr);
191
						}
192
						}
192
					}
193
					}
193
				}
194
				}
194
				fclose($fd2);
195
				fclose($fd2);
195
 
196
 
196
				// so now after all that mess $thread_head contains a full thread tree
197
				// so now after all that mess $thread_head contains a full thread tree
197
				// first build the depth of each message based on 'in-reply-to' and 'references'
198
				// first build the depth of each message based on 'in-reply-to' and 'references'
198
				unset($thread_temp);
199
				unset($thread_temp);
199
				$thread_temp = NULL;
200
				$thread_temp = NULL;
200
				$thread_curr =& $thread_head->next;
201
				$thread_curr =& $thread_head->next;
201
				while (get_class($thread_curr) == 'ezmlm_thread') {
202
				while (get_class($thread_curr) == 'ezmlm_thread') {
202
					unset($thread_temp);
203
					unset($thread_temp);
203
					$thread_temp = NULL;
204
					$thread_temp = NULL;
204
 
205
 
205
					if ($thread_curr->inreply != '') { $thread_temp =& $thread_head->find_msgid($thread_curr->inreply); }
206
					if ($thread_curr->inreply != '') { $thread_temp =& $thread_head->find_msgid($thread_curr->inreply); }
206
					if ($thread_temp == NULL) {
207
					if ($thread_temp == NULL) {
207
						if ($thread_curr->references != '') {
208
						if ($thread_curr->references != '') {
208
							$refs = preg_split('/ /', $thread_curr->references);
209
							$refs = preg_split('/ /', $thread_curr->references);
209
							$refs = array_pop($refs);
210
							$refs = array_pop($refs);
210
							$thread_temp =& $thread_head->find_msgid($refs);
211
							$thread_temp =& $thread_head->find_msgid($refs);
211
						}
212
						}
212
					}
213
					}
213
					if ($thread_temp == NULL) {
214
					if ($thread_temp == NULL) {
214
						// we couldn't find anything... set depth to 1, the default
215
						// we couldn't find anything... set depth to 1, the default
215
						$thread_curr->depth = 1;
216
						$thread_curr->depth = 1;
216
					} else {
217
					} else {
217
						// we found a reference, set it to it's depth + 1
218
						// we found a reference, set it to it's depth + 1
218
						$thread_curr->depth = $thread_temp->depth + 1;
219
						$thread_curr->depth = $thread_temp->depth + 1;
219
					}
220
					}
220
					$thread_curr =& $thread_curr->next;
221
					$thread_curr =& $thread_curr->next;
221
				}
222
				}
222
 
223
 
223
				// now write it to a temp file named MONTH-SEQ where seq is cronologic sequence order of the thread.
224
				// now write it to a temp file named MONTH-SEQ where seq is cronologic sequence order of the thread.
224
				if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
225
				if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
225
					@mkdir($this->tempdir . "/ezmlm-php-" . $this->listname, 0755);
226
					@mkdir($this->tempdir . "/ezmlm-php-" . $this->listname, 0755);
226
					if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
227
					if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
227
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month, "a");
228
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month, "a");
228
					} else {
229
					} else {
229
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
230
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
230
					}
231
					}
231
				} else {
232
				} else {
232
					$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
233
					$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
233
				}
234
				}
234
				fputs($fd2,$this->thread_to_html($thread_head));
235
				fputs($fd2,$this->thread_to_html($thread_head));
235
				fclose($fd2);
236
				fclose($fd2);
236
			}
237
			}
237
		}
238
		}
238
 
239
 
239
		// finally store our checksum
240
		// finally store our checksum
240
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
241
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
241
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum","w+");
242
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum","w+");
242
		} else {
243
		} else {
243
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum","w+");
244
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum","w+");
244
		}
245
		}
245
		fputs($fd2,"md5:" . $this->md5_of_file($this->listdir . "/archive/threads/" . $month) . "\n");
246
		fputs($fd2,"md5:" . $this->md5_of_file($this->listdir . "/archive/threads/" . $month) . "\n");
246
		fclose($fd2);
247
		fclose($fd2);
247
		fclose($fd1);
248
		fclose($fd1);
248
 
249
 
249
		return TRUE;
250
		return TRUE;
250
	}
251
	}
251
 
252
 
252
	// listmessages: prints out a nice little calendar and displays the message
253
	// listmessages: prints out a nice little calendar and displays the message
253
	// totals for each month. The link jumps to the thread listing.
254
	// totals for each month. The link jumps to the thread listing.
254
    // On lit le répetoire archive/threads/ qui contient un fichier par moi avec tous les thread, par sujet 
255
    // On lit le répertoire archive/threads/ qui contient un fichier par moi avec tous les thread, par sujet 
255
    // Présentés comme suit 
256
    // Présentés comme suit 
256
    // num_thread:hash [taille_du_thread] Sujet du thread (le dernier)
257
    // num_thread:hash [taille_du_thread] Sujet du thread (le dernier)
257
    // les messages sont rangés par leur numéro
258
    // les messages sont rangés par leur numéro
258
	function listmessages() {
259
	function listmessages() {
259
        if (!is_dir($this->listdir . "/archive/threads/")) {
260
        if (!is_dir($this->listdir . "/archive/threads/")) {
260
            return false ;
261
            return false ;
261
        }
262
        }
-
 
263
        $threadcount = array();
-
 
264
 
262
		$dir = opendir($this->listdir . "/archive/threads/");
265
		$repertoire_archive = opendir($this->listdir . "/archive/");
-
 
266
 
263
		while ($item = readdir($dir)) {
267
		while (false !== ($item = readdir($repertoire_archive))) {
264
			if (($item == ".") or ($item == "..")) { continue; }
268
			// $item contient les noms des repertoires
265
            // Le nom du fichier est annéemoi ex 200501 pour janvier 2005
269
			// on ne garde que ceux qui sont des chiffres
266
            
270
 
267
			if (preg_match("/^[0-9][0-9][0-9][0-9][0-9][0-9]/",$item)) {
271
			if (preg_match('/[0-9]+/', $item)) {
268
                // on ouvre chaque fichier en lecture
272
				// on ouvre le fichier d index de chaque repertoire
269
				$fd = fopen($this->listdir . "/archive/threads/" . $item, "r");
273
				$fichier_index = fopen($this->listdir.'/archive/'.$item.'/index', 'r');
270
				$count = 0; // on initialise un compteur
274
				$compteur = 0 ;
-
 
275
				
271
				while(!feof($fd)) {
276
				while (!feof($fichier_index)) {
-
 
277
					// On ignore la premiere ligne
-
 
278
					$temp = fgets($fichier_index, 4096);
-
 
279
					// dans la seconde on recupere la date
272
					$curthread = fgets($fd,4096);
280
					$temp = fgets($fichier_index, 4096);
273
					$num = preg_replace("/.*\[([0-9].*)\].*/", "\\1", $curthread); // $num contient le nbre de message du thread
281
					preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9])/', $temp, $match) ;
274
					$count = $count + $num;
282
					if ($match[0] != '') {
-
 
283
						$threadmonth = date('n', strtotime($match[0]))  ;
-
 
284
						$threadyear = date('Y', strtotime($match[0])) ;
-
 
285
						$threadcount[$threadyear][$threadmonth]++;
-
 
286
					}
275
				}
287
				}
276
				$threadyear = substr($item,0,4);
288
				fclose ($fichier_index);
277
				$threadmonth = substr($item,4,2);
-
 
278
                // on construit un tableau à 2 entrée [année][mois] = nbre_message
-
 
279
				$threadcount[$threadyear][$threadmonth] = $count;
-
 
280
			}
289
			}
281
		}
290
		}
282
		closedir($dir);
-
 
283
 
291
		
284
		arsort($threadcount);       // modifié par alex, car remplace l'année par 0 
-
 
285
        
-
 
286
        // La partie qui suit, simple, crée la table avec le nombre de message échangé chaque mois
292
        // La partie qui suit, simple, crée la table avec le nombre de message échangé chaque mois
287
		$res = '<table id="petit_calendrier">'."\n";
293
		$res = '<table id="petit_calendrier">'."\n";
288
		$res .= " <tr>\n";
294
		$res .= " <tr>\n";
289
		$res .= "  <td></td>" ;
295
		$res .= "  <td></td>" ;
290
        foreach ($GLOBALS['mois'] as $valeur) $res .= '<td>'.$valeur.'</td>' ;
296
        foreach ($GLOBALS['mois'] as $valeur) $res .= '<td>'.$valeur.'</td>' ;
291
		$res .=" </tr>\n";
297
		$res .=" </tr>\n";
292
 
298
 
293
		while (list($key,$val) = each($threadcount)) {
299
		while (list($key,$val) = each($threadcount)) {
294
			$res .= " <tr>\n";
300
			$res .= " <tr>\n";
295
			$res .= "  <td>$key</td>";
301
			$res .= "  <td>$key</td>";
296
			for ($i = 1; $i <= 12; $i++) {
302
			for ($i = 1; $i <= 12; $i++) {
297
				if ($i < 10) { $key2 = "0" . $i; }
-
 
298
				else { $key2 = $i; }
-
 
299
				if (isset($threadcount[$key][$key2]) && $threadcount[$key][$key2] > 0) {
303
				if (isset($threadcount[$key][$i]) && $threadcount[$key][$i] > 0) {
300
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\" valign=\"middle\">";
304
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\" valign=\"middle\">";
301
                    $res .= $this->makelink("action=show_month&amp;actionargs[]=$key$key2",$threadcount[$key][$key2]);
305
                    $res .= $this->makelink('action=show_month&amp;actionargs[]='.$key.($i < 10 ? '0'.$i:$i),$threadcount[$key][$i]);
302
					$res .= "</td>";
306
					$res .= "</td>";
303
				} else {
307
				} else {
304
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\"></td>";
308
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\"></td>";
305
				}
309
				}
306
			}
310
			}
307
			$res .= "</tr>\n";
311
			$res .= "</tr>\n";
308
		}
312
		}
309
		$res .= "</table>\n";
313
		$res .= "</table>\n";
310
        echo $res ;
314
        echo $res ;
311
	}
315
	}
312
}
316
}
313
 
317
 
314
// CLASS: ezmlm-thread is a quick little class to allow us to define
318
// CLASS: ezmlm-thread is a quick little class to allow us to define
315
// a structure of the current thread in a single-linked list.
319
// a structure of the current thread in a single-linked list.
316
// it's a little messy since php doesn't support pointers like C does
320
// it's a little messy since php doesn't support pointers like C does
317
// so we have to use references and a head object to append to the list.
321
// so we have to use references and a head object to append to the list.
318
class ezmlm_thread {
322
class ezmlm_thread {
319
	var $next;
323
	var $next;
320
	var $depth;
324
	var $depth;
321
	var $file;
325
	var $file;
322
	var $msgid;
326
	var $msgid;
323
	var $inreply;
327
	var $inreply;
324
	var $references;
328
	var $references;
325
	function append($thread) {
329
	function append($thread) {
326
		$thread_curr =& $this;
330
		$thread_curr =& $this;
327
		while ($thread_curr->next != NULL) {
331
		while ($thread_curr->next != NULL) {
328
			$thread_curr =& $thread_curr->next;
332
			$thread_curr =& $thread_curr->next;
329
		}
333
		}
330
		$thread_curr->next = $thread;
334
		$thread_curr->next = $thread;
331
	}
335
	}
332
	function &find_msgid($msgid) {
336
	function &find_msgid($msgid) {
333
		$thread_curr =& $this;
337
		$thread_curr =& $this;
334
		while ($thread_curr->next != NULL) {
338
		while ($thread_curr->next != NULL) {
335
			if (trim($thread_curr->msgid) == trim($msgid)) { return $thread_curr; }
339
			if (trim($thread_curr->msgid) == trim($msgid)) { return $thread_curr; }
336
			$thread_curr =& $thread_curr->next;
340
			$thread_curr =& $thread_curr->next;
337
		}
341
		}
338
		return NULL;
342
		return NULL;
339
	}
343
	}
340
	function ezmlm_thread($depth,$file,$msgid) {
344
	function ezmlm_thread($depth,$file,$msgid) {
341
		$this->depth = $depth;
345
		$this->depth = $depth;
342
		$this->file  = $file;
346
		$this->file  = $file;
343
		$this->msgid = $msgid;
347
		$this->msgid = $msgid;
344
		$this->next = NULL;
348
		$this->next = NULL;
345
	}
349
	}
346
}
350
}
347
?>
351
?>