Subversion Repositories Applications.projet

Rev

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

Rev 208 Rev 308
1
<?php
1
<?php
2
// $Id: ezmlm-threads.php,v 1.5 2007-04-19 15:34:35 neiluj Exp $
2
// $Id: ezmlm-threads.php,v 1.6 2008-08-25 15:19:15 alexandre_tb 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
require_once ('ezmlm-langue-fr.php');
14
 
14
 
15
// 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)
16
class ezmlm_threads extends ezmlm_php {
16
class ezmlm_threads extends ezmlm_php {
17
 
17
 
18
	// load: this is the main function that should be called.
18
	// load: this is the main function that should be called.
19
	// 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
20
	// other wise it loads them and calls display
20
	// other wise it loads them and calls display
21
	function load($month) {
21
	function load($month) {
22
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
22
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
23
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum";
23
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum";
24
		} else {
24
		} else {
25
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum";
25
			$checksum = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum";
26
		}
26
		}
27
        $md5 = '' ;
27
        $md5 = '' ;
28
		if (!is_file($checksum)) {
28
		if (!is_file($checksum)) {
29
			$this->build($month);
29
			$this->build($month);
30
		} else {
30
		} else {
31
			$fd = fopen($checksum,"r");
31
			$fd = fopen($checksum,"r");
32
			while (!preg_match('/^md5:/', $md5)) { $md5 = fgets($fd,4096); }
32
			while (!preg_match('/^md5:/', $md5)) { $md5 = fgets($fd,4096); }
33
			fclose($fd);
33
			fclose($fd);
34
			$md5 = rtrim(preg_replace('/^md5:/', '', $md5), "\n");
34
			$md5 = rtrim(preg_replace('/^md5:/', '', $md5), "\n");
35
			if ($md5 != $this->md5_of_file($this->listdir . "/archive/threads/" . $month)) {
35
			if ($md5 != $this->md5_of_file($this->listdir . "/archive/threads/" . $month)) {
36
				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";
37
				$this->build($month);
37
				$this->build($month);
38
			}
38
			}
39
		}
39
		}
40
		$this->display($month);
40
		$this->display($month);
41
	}
41
	}
42
 
42
 
43
	// 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
44
	// 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
45
	// view the threads
45
	// view the threads
46
	function display($month) {
46
	function display($month) {
47
		$seq = 0;
47
		$seq = 0;
48
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
48
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
49
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month;
49
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month;
50
		} else {
50
		} else {
51
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month;
51
			$cache = $this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month;
52
		}
52
		}
53
        // Le lien par date et par thread
53
        // Le lien par date et par thread
54
        echo '[ '.$this->makelink('action=show_month&amp;actionargs[]='.$month, 'par date').' ]' ;
54
        echo '[ '.$this->makelink('action=show_month&amp;actionargs[]='.$month, 'par date').' ]' ;
55
		$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');
56
        // remplacé par le tableau globals $mois dans ezmlm.php
56
        // remplacé par le tableau globals $mois dans ezmlm.php
57
		print '<h2>'.FIL_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";
58
		
58
		
59
		print '<table class="table_cadre">'."\n";
59
		print '<table class="table_cadre">'."\n";
60
		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";
61
		print '<tr><td colspan="3"><hr /></td></tr>'."\n";
61
		print '<tr><td colspan="3"><hr /></td></tr>'."\n";
62
		$ctc = 0;
62
		$ctc = 0;
63
 
63
 
64
		if (is_file($cache)) {
64
		if (is_file($cache)) {
65
			include($cache);
65
			include($cache);
66
		}
66
		}
67
		print '<tr><td colspan="3"></td></tr>'."\n";
67
		print '<tr><td colspan="3"></td></tr>'."\n";
68
        print '</table>'."\n";
68
        print '</table>'."\n";
69
        }
69
        }
70
 
70
 
71
 
71
 
72
	function thread_to_html($thread) {
72
	function thread_to_html($thread) {
73
		$html = '';
73
		$html = '';
74
		$lastdepth = -1;
74
		$lastdepth = -1;
75
        $ctc = 0 ;
75
        $ctc = 0 ;
76
		$thread_curr = $thread;
76
		$thread_curr = $thread;
77
        $class = array ('ligne_paire', 'ligne_impaire') ;
77
        $class = array ('ligne_paire', 'ligne_impaire') ;
78
		while ($thread_curr != NULL) {
78
		while ($thread_curr != NULL) {
79
            preg_match ('!/archive/([0-9]*)/([0-9]*)!', $thread_curr->file, $match) ;
79
            preg_match ('!/archive/([0-9]*)/([0-9]*)!', $thread_curr->file, $match) ;
80
            if (!isset($GLOBALS['fichiers_analyses'][$match[1]][$match[2]])) {
80
            if (!isset($GLOBALS['fichiers_analyses'][$match[1]][$match[2]])) {
81
                $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
81
                $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
82
                $mimeDecode = new Mail_mimeDecode($message) ;
82
                $mimeDecode = new Mail_mimeDecode($message) ;
83
                $mailDecode = $mimeDecode->decode() ;
83
                $mailDecode = $mimeDecode->decode() ;
84
                //$msg = new ezmlm_parser();
84
                //$msg = new ezmlm_parser();
85
                //$msg->parse_file($this->listdir . $thread_curr->file, TRUE);
85
                //$msg->parse_file($this->listdir . $thread_curr->file, TRUE);
86
                
86
                
87
            } else {
87
            } else {
88
                $mailDecode = $GLOBALS['fichiers_analyses'][$match[1]][$match[2]] ;
88
                $mailDecode = $GLOBALS['fichiers_analyses'][$match[1]][$match[2]] ;
89
            }   
89
            }   
90
            $actionargs = preg_split("/\//", $thread_curr->file);
90
            $actionargs = preg_split("/\//", $thread_curr->file);
91
			$html .= '<tr class="'.$class[$ctc].'">'."\n";
91
			$html .= '<tr class="'.$class[$ctc].'">'."\n";
92
			$html .= '<td>'.$actionargs[2].$actionargs[3].'</td><td>';
92
			$html .= '<td>'.$actionargs[2].$actionargs[3].'</td><td>';
93
			$html .= $this->makelink('action=show_author_msgs&amp;actionargs[]='. 
93
			$html .= $this->makelink('action=show_author_msgs&amp;actionargs[]='. 
94
                    $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)));
95
			$html .= '</td>'."\n";
95
			$html .= '</td>'."\n";
96
			$html .= '<td><b>';
96
			$html .= '<td><b>';
97
			//$html .= " <a name=\"" . urlencode($thread_curr->file) . "\">";    A quoi ça sert ?
97
			//$html .= " <a name=\"" . urlencode($thread_curr->file) . "\">";    A quoi ça sert ?
98
			for ($i = 0; $i < $thread_curr->depth; $i++) {
98
			for ($i = 0; $i < $thread_curr->depth; $i++) {
99
				$html .= "&nbsp;&nbsp;";
99
				$html .= "&nbsp;&nbsp;";
100
			}
100
			}
101
			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)) {
102
				$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)));
103
				$subject = $subject . "...";
103
				$subject = $subject . "...";
104
			} else {
104
			} else {
105
				$subject = $this->decode_iso($mailDecode->headers['subject']);
105
				$subject = $this->decode_iso($mailDecode->headers['subject']);
106
			}
106
			}
107
 
107
 
108
			
108
			
109
			$subject = preg_replace("/\[" . $this->listname . "\]/", "", $subject);
109
			$subject = preg_replace("/\[" . $this->listname . "\]/", "", $subject);
110
			$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);
111
			$html .= "</b></td>\n";
111
			$html .= "</b></td>\n";
112
			$html .= '<td>' .$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
112
			$html .= '<td>' .$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
113
			$html .= "</tr>\n";
113
			$html .= "</tr>\n";
114
 
114
 
115
			$ctc++;
115
			$ctc++;
116
			if ($ctc == count($this->tablecolours)) { $ctc = 0; }
116
			if ($ctc == count($this->tablecolours)) { $ctc = 0; }
117
 
117
 
118
			$lastdepth = $thread_curr->depth;
118
			$lastdepth = $thread_curr->depth;
119
			$thread_curr = $thread_curr->next;
119
			$thread_curr = $thread_curr->next;
120
		}
120
		}
121
 
121
 
122
		$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";
123
		return $html;
123
		return $html;
124
	}
124
	}
125
 
125
 
126
	// 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
127
	// 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
128
	// stored in $this->tmpdir;
128
	// stored in $this->tmpdir;
129
	function build($month) {
129
	function build($month) {
130
		if (!is_file($this->listdir . "/archive/threads/" . $month)) { return FALSE; }
130
		if (!is_file($this->listdir . "/archive/threads/" . $month)) { return FALSE; }
131
 
131
 
132
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
132
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
133
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month,"w+");
133
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month,"w+");
134
                } else {
134
                } else {
135
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month,"w+");
135
                        $fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month,"w+");
136
                }
136
                }
137
		fclose($fd2);
137
		fclose($fd2);
138
        $i=0;
138
        $i=0;
139
        // ouverture du fichier thread de ezmlm
139
        // ouverture du fichier thread de ezmlm
140
        // Ils sont classés mois par mois
140
        // Ils sont classés mois par mois
141
		$fd1 = fopen($this->listdir . "/archive/threads/" . $month, "r");
141
		$fd1 = fopen($this->listdir . "/archive/threads/" . $month, "r");
142
		while (!feof($fd1)) {
142
		while (!feof($fd1)) {
143
			$line = fgets($fd1,4096);
143
			$line = fgets($fd1,4096);
144
			if (preg_match('/^[0-9]*\:[a-z]* \[.*/', $line)) {
144
			if (preg_match('/^[0-9]*\:[a-z]* \[.*/', $line)) {
145
				// valid ezmlm thread file entry
145
				// valid ezmlm thread file entry
146
                
146
                
147
                // On place dans $subjectfile le chemin vers le fichier sujet 
147
                // On place dans $subjectfile le chemin vers le fichier sujet 
148
				$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $line);
148
				$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $line);
149
                $subjectfile = substr($subjectfile,0,2) . '/' . substr($subjectfile,2,18);
149
                $subjectfile = substr($subjectfile,0,2) . '/' . substr($subjectfile,2,18);
150
 
150
 
151
				$thread_head = NULL;
151
				$thread_head = NULL;
152
				$thread_curr = NULL;
152
				$thread_curr = NULL;
153
				$thread_temp = NULL;
153
				$thread_temp = NULL;
154
				$thread_depth = 1;
154
				$thread_depth = 1;
155
 
155
 
156
				if (!is_file($this->listdir . "/archive/subjects/" . $subjectfile)) { continue; }
156
				if (!is_file($this->listdir . "/archive/subjects/" . $subjectfile)) { continue; }
157
                // on ouvre le fichier sujet 
157
                // on ouvre le fichier sujet 
158
                // 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
159
                // sur les autres lignes :
159
                // sur les autres lignes :
160
                // num_message:annéemois:hash_auteur nom_auteur
160
                // num_message:annéemois:hash_auteur nom_auteur
161
				$fd2 = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r");
161
				$fd2 = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r");
162
				while (!feof($fd2)) {
162
				while (!feof($fd2)) {
163
					$line2 = fgets($fd2,4096);
163
					$line2 = fgets($fd2,4096);
164
					if (preg_match('/^[0-9]/',$line2)) {
164
					if (preg_match('/^[0-9]/',$line2)) {
165
						$msgnum = preg_replace('/^([0-9]*):.*/', '\\1', $line2);
165
						$msgnum = preg_replace('/^([0-9]*):.*/', '\\1', $line2);
166
						$msgfile = $msgnum % 100;
166
						$msgfile = $msgnum % 100;
167
                        $msgdir  = (int)($msgnum / 100);
167
                        $msgdir  = (int)($msgnum / 100);
168
						if ($msgfile < 10) { $msgfile = "0" . $msgfile; }
168
						if ($msgfile < 10) { $msgfile = "0" . $msgfile; }
169
						//$msg = new ezmlm_parser();
169
						//$msg = new ezmlm_parser();
170
						//$msg->parse_file_headers($this->listdir . "/archive/" . $msgdir . "/" . $msgfile, TRUE);
170
						//$msg->parse_file_headers($this->listdir . "/archive/" . $msgdir . "/" . $msgfile, TRUE);
171
                        
171
                        
172
                        $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
172
                        $message = file_get_contents($this->listdir . "/archive/" . $msgdir . "/" . $msgfile) ;
173
                        $mimeDecode = new Mail_mimeDecode($message) ;
173
                        $mimeDecode = new Mail_mimeDecode($message) ;
174
                        $mailDecode = $mimeDecode->decode() ;
174
                        $mailDecode = $mimeDecode->decode() ;
175
                        
175
                        
176
                        
176
                        
177
                        
177
                        
178
                        // On stocke le fichier analysée pour réutilisation ultàrieure
178
                        // On stocke le fichier analysée pour réutilisation ultàrieure
179
                        $GLOBALS['fichiers_analyses'][$msgdir][$msgfile] =  $mailDecode ;
179
                        $GLOBALS['fichiers_analyses'][$msgdir][$msgfile] =  $mailDecode ;
180
						$msgid = (isset ($mailDecode->headers['message-id']) ? $mailDecode->headers['message-id'] : '');
180
						$msgid = (isset ($mailDecode->headers['message-id']) ? $mailDecode->headers['message-id'] : '');
181
						$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'] : '');
182
						$references = (isset ($mailDecode->headers['references']) ? $mailDecode->headers['references'] : '') ;
182
						$references = (isset ($mailDecode->headers['references']) ? $mailDecode->headers['references'] : '') ;
183
						$thread_depth = 1;
183
						$thread_depth = 1;
184
 
184
 
185
						if ($thread_head == NULL) {
185
						if ($thread_head == NULL) {
186
							$thread_head = new ezmlm_thread(0,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
186
							$thread_head = new ezmlm_thread(0,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
187
						} else {
187
						} else {
188
							$thread_curr = new ezmlm_thread($depth,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
188
							$thread_curr = new ezmlm_thread($depth,'/archive/' . $msgdir . '/' . $msgfile,$msgid);
189
							if ($inreply != '') { $thread_curr->inreply = $inreply; }
189
							if ($inreply != '') { $thread_curr->inreply = $inreply; }
190
							if ($references != '') { $thread_curr->references = $references; }
190
							if ($references != '') { $thread_curr->references = $references; }
191
							$thread_head->append($thread_curr);
191
							$thread_head->append($thread_curr);
192
						}
192
						}
193
					}
193
					}
194
				}
194
				}
195
				fclose($fd2);
195
				fclose($fd2);
196
 
196
 
197
				// 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
198
				// 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'
199
				unset($thread_temp);
199
				unset($thread_temp);
200
				$thread_temp = NULL;
200
				$thread_temp = NULL;
201
				$thread_curr =& $thread_head->next;
201
				$thread_curr =& $thread_head->next;
202
				while (get_class($thread_curr) == 'ezmlm_thread') {
202
				while (get_class($thread_curr) == 'ezmlm_thread') {
203
					unset($thread_temp);
203
					unset($thread_temp);
204
					$thread_temp = NULL;
204
					$thread_temp = NULL;
205
 
205
 
206
					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); }
207
					if ($thread_temp == NULL) {
207
					if ($thread_temp == NULL) {
208
						if ($thread_curr->references != '') {
208
						if ($thread_curr->references != '') {
209
							$refs = preg_split('/ /', $thread_curr->references);
209
							$refs = preg_split('/ /', $thread_curr->references);
210
							$refs = array_pop($refs);
210
							$refs = array_pop($refs);
211
							$thread_temp =& $thread_head->find_msgid($refs);
211
							$thread_temp =& $thread_head->find_msgid($refs);
212
						}
212
						}
213
					}
213
					}
214
					if ($thread_temp == NULL) {
214
					if ($thread_temp == NULL) {
215
						// we couldn't find anything... set depth to 1, the default
215
						// we couldn't find anything... set depth to 1, the default
216
						$thread_curr->depth = 1;
216
						$thread_curr->depth = 1;
217
					} else {
217
					} else {
218
						// we found a reference, set it to it's depth + 1
218
						// we found a reference, set it to it's depth + 1
219
						$thread_curr->depth = $thread_temp->depth + 1;
219
						$thread_curr->depth = $thread_temp->depth + 1;
220
					}
220
					}
221
					$thread_curr =& $thread_curr->next;
221
					$thread_curr =& $thread_curr->next;
222
				}
222
				}
223
 
223
 
224
				// 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.
225
				if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
225
				if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
226
					@mkdir($this->tempdir . "/ezmlm-php-" . $this->listname, 0755);
226
					@mkdir($this->tempdir . "/ezmlm-php-" . $this->listname, 0755);
227
					if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
227
					if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
228
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month, "a");
228
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month, "a");
229
					} else {
229
					} else {
230
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
230
						$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
231
					}
231
					}
232
				} else {
232
				} else {
233
					$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
233
					$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month, "a");
234
				}
234
				}
235
				fputs($fd2,$this->thread_to_html($thread_head));
235
				fputs($fd2,$this->thread_to_html($thread_head));
236
				fclose($fd2);
236
				fclose($fd2);
237
			}
237
			}
238
		}
238
		}
239
 
239
 
240
		// finally store our checksum
240
		// finally store our checksum
241
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
241
		if (!is_dir($this->tempdir . "/ezmlm-php-" . $this->listname)) {
242
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum","w+");
242
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "-" . $month . "-" . "checksum","w+");
243
		} else {
243
		} else {
244
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum","w+");
244
			$fd2 = fopen($this->tempdir . "/ezmlm-php-" . $this->listname . "/" . $month . "-" . "checksum","w+");
245
		}
245
		}
246
		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");
247
		fclose($fd2);
247
		fclose($fd2);
248
		fclose($fd1);
248
		fclose($fd1);
249
 
249
 
250
		return TRUE;
250
		return TRUE;
251
	}
251
	}
252
 
252
 
253
	// listmessages: prints out a nice little calendar and displays the message
253
	// listmessages: prints out a nice little calendar and displays the message
254
	// totals for each month. The link jumps to the thread listing.
254
	// totals for each month. The link jumps to the thread listing.
255
    // On lit le répertoire archive/threads/ qui contient un fichier par moi avec tous les thread, par sujet 
255
    // On lit le repetoire archive/threads/ qui contient un fichier par moi avec tous les thread, par sujet 
256
    // Présentés comme suit 
256
    // Presentes comme suit 
257
    // num_thread:hash [taille_du_thread] Sujet du thread (le dernier)
257
    // num_thread:hash [taille_du_thread] Sujet du thread (le dernier)
258
    // les messages sont rangés par leur numéro
258
    // les messages sont ranges par leur numero
259
	function listmessages() {
259
	function listmessages() {
260
        if (!is_dir($this->listdir . "/archive/threads/")) {
260
        if (!is_dir($this->listdir . "/archive/threads/")) {
261
            return false ;
261
            return false ;
262
        }
262
        }
-
 
263
        
-
 
264
        $res = '<table id="petit_calendrier">'."\n";
-
 
265
        $res .= " <tr>\n";
-
 
266
		$res .= "  <td></td>" ;
-
 
267
        foreach ($GLOBALS['mois'] as $valeur) $res .= '<th>'.$valeur.'</th>' ;
-
 
268
		$res .=" </tr>\n";
-
 
269
        $res .= $this->calendrierMessage();
-
 
270
        $res .= "</table>\n";
-
 
271
        return $res;
-
 
272
        /*
263
        $threadcount = array();
273
        $threadcount = array();
264
 
274
 
265
		$repertoire_archive = opendir($this->listdir . "/archive/");
275
		$repertoire_archive = opendir($this->listdir . "/archive/");
266
 
-
 
-
 
276
		$tableau_annee = array();
267
		while (false !== ($item = readdir($repertoire_archive))) {
277
		while (false !== ($item = readdir($repertoire_archive))) {
268
			// $item contient les noms des repertoires
278
			// $item contient les noms des repertoires
269
			// on ne garde que ceux qui sont des chiffres
279
			// on ne garde que ceux qui sont des chiffres
270
 
280
 
271
			if (preg_match('/[0-9]+/', $item)) {
281
			if (preg_match('/[0-9]+/', $item)) {
272
				// on ouvre le fichier d index de chaque repertoire
282
				// on ouvre le fichier d index de chaque repertoire
273
				$fichier_index = fopen($this->listdir.'/archive/'.$item.'/index', 'r');
283
				$fichier_index = fopen($this->listdir.'/archive/'.$item.'/index', 'r');
274
				$compteur = 0 ;
284
				$compteur = 0 ;
275
				
285
				
276
				while (!feof($fichier_index)) {
286
				while (!feof($fichier_index)) {
277
					// On ignore la premiere ligne
287
					// On ignore la premiere ligne
278
					$temp = fgets($fichier_index, 4096);
288
					$temp = fgets($fichier_index, 4096);
279
					// dans la seconde on recupere la date
289
					// dans la seconde on recupere la date
280
					$temp = fgets($fichier_index, 4096);
290
					$temp = fgets($fichier_index, 4096);
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) ;
291
					preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9])/', $temp, $match) ;
282
					if ($match[0] != '') {
292
					if ($match[0] != '') {
-
 
293
						
283
						$threadmonth = date('n', strtotime($match[0]))  ;
294
						$threadmonth = date('n', strtotime($match[0]))  ;
284
						$threadyear = date('Y', strtotime($match[0])) ;
295
						$threadyear = date('Y', strtotime($match[0])) ;
285
						$threadcount[$threadyear][$threadmonth]++;
296
						$threadcount[$threadyear][$threadmonth]++;
-
 
297
						if (!in_array($threadyear, $tableau_annee)) array_push ($tableau_annee, $threadyear);
286
					}
298
					}
287
				}
299
				}
288
				fclose ($fichier_index);
300
				fclose ($fichier_index);
289
			}
301
			}
290
		}
302
		}
291
		
-
 
-
 
303
		if (count($threadcount) == 0) return 'Il n\y a pas de messages dans les archives';
292
        // La partie qui suit, simple, crée la table avec le nombre de message échangé chaque mois
304
        // La partie qui suit, simple, cree la table avec le nombre de message echange chaque mois
293
		$res = '<table id="petit_calendrier">'."\n";
305
		$res = '<table id="petit_calendrier">'."\n";
294
		$res .= " <tr>\n";
306
		$res .= " <tr>\n";
295
		$res .= "  <td></td>" ;
307
		$res .= "  <td></td>" ;
296
        foreach ($GLOBALS['mois'] as $valeur) $res .= '<td>'.$valeur.'</td>' ;
308
        foreach ($GLOBALS['mois'] as $valeur) $res .= '<th>'.$valeur.'</th>' ;
297
		$res .=" </tr>\n";
309
		$res .=" </tr>\n";
298
 
-
 
-
 
310
		arsort($tableau_annee);
299
		while (list($key,$val) = each($threadcount)) {
311
		foreach ($tableau_annee as $annee) {
300
			$res .= " <tr>\n";
312
			$res .= " <tr>\n";
301
			$res .= "  <td>$key</td>";
313
			$res .= '  <td class="col_annee">'.$annee.'</td>';
302
			for ($i = 1; $i <= 12; $i++) {
314
			for ($i = 1; $i <= 12; $i++) {
-
 
315
				$res .= '<td class="mois">';
303
				if (isset($threadcount[$key][$i]) && $threadcount[$key][$i] > 0) {
316
				if (isset($threadcount[$annee][$i]) && $threadcount[$annee][$i] > 0) {
304
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\" valign=\"middle\">";
-
 
305
                    $res .= $this->makelink('action=show_month&amp;actionargs[]='.$key.($i < 10 ? '0'.$i:$i),$threadcount[$key][$i]);
317
                    $res .= $this->makelink('action=show_month&amp;actionargs[]='.$annee.($i < 10 ? '0'.$i:$i),$threadcount[$annee][$i]);
306
					$res .= "</td>";
-
 
307
				} else {
-
 
308
					$res .= "<td bgcolor=\"" . $this->tablecolours[0] . "\"></td>";
-
 
309
				}
318
				} 
-
 
319
				$res .= '</td>';
310
			}
320
			}
311
			$res .= "</tr>\n";
321
			$res .= '</tr>'."\n";
312
		}
322
		}
313
		$res .= "</table>\n";
323
		$res .= "</table>\n";
314
        echo $res ;
324
        return $res ;
-
 
325
        */
-
 
326
	}
-
 
327
	/*
-
 
328
	 *  Cree un fichier liste.calendrierPermanent qui contient  
-
 
329
	 *  le nombre de message par mois pour toutes les annees 
-
 
330
	 *  depuis le debut de la liste sauf la derniere
-
 
331
	 * 
-
 
332
	 */
-
 
333
	function calculeCalendrierPermanent($Annnee = '') {
-
 
334
		$numArchive = $this->getNumArchive();
-
 
335
		$dernierRepertoire = floor($numArchive / 100);
-
 
336
		
-
 
337
		$threadcount = array();
-
 
338
		$tableau_annee = array();
-
 
339
		
-
 
340
		
-
 
341
		for ($rep_courant = $dernierRepertoire; $rep_courant >= 0; $rep_courant--) {
-
 
342
			$fichier_index = file ($this->listdir.'/archive/'.$rep_courant.'/index', FILE_IGNORE_NEW_LINES);
-
 
343
 
-
 
344
			// On parcours le fichier a l envers
-
 
345
			for ($j = count($fichier_index)-1; $j >= 0; $j-=2) {
-
 
346
				preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9])/', $fichier_index[$j], $match) ;
-
 
347
				if ($match[0] != '') {
-
 
348
					$threadmonth = date('n', strtotime($match[0]))  ;
-
 
349
					$threadyear = date('Y', strtotime($match[0])) ;
-
 
350
					if ($Annnee != '') {
-
 
351
						if ($threadyear < date('Y')) {
-
 
352
							$sortir = true;
-
 
353
							break;	
-
 
354
						}
-
 
355
					}  else {
-
 
356
						if ($threadyear == date('Y')) continue;	
-
 
357
					}
-
 
358
					$threadcount[$threadyear][$threadmonth]++;
-
 
359
					if (!in_array($threadyear, $tableau_annee)) array_push ($tableau_annee, $threadyear);
-
 
360
				}
-
 
361
			}
-
 
362
			if ($sortir) break;
-
 
363
		}
-
 
364
		$res = ''; 
-
 
365
		arsort($tableau_annee);
-
 
366
		foreach ($tableau_annee as $annee) {
-
 
367
			$res .= " <tr>\n";
-
 
368
			$res .= '  <td class="col_annee">'.$annee.'</td>';
-
 
369
			for ($i = 1; $i <= 12; $i++) {
-
 
370
				$res .= '<td class="mois">';
-
 
371
				if (isset($threadcount[$annee][$i]) && $threadcount[$annee][$i] > 0) {
-
 
372
                    $res .= $this->makelink('action=show_month&amp;actionargs[]='.$annee.($i < 10 ? '0'.$i:$i),$threadcount[$annee][$i]);
-
 
373
				} 
-
 
374
				$res .= '</td>';
-
 
375
			}
-
 
376
			$res .= '</tr>'."\n";
-
 
377
		}
-
 
378
		return $res;
-
 
379
	}
-
 
380
	function ecrireFichierCalendrier() {
-
 
381
		$html = $this->calculeCalendrierPermanent();
-
 
382
		$f = fopen ('tmp/'.$this->listname.'.calendrier', 'w') ;
-
 
383
		fwrite ($f, $html);
-
 
384
		fclose($f);
-
 
385
		return $html;
-
 
386
	}
-
 
387
	
-
 
388
	function calendrierMessage() {
-
 
389
		$html = '';
-
 
390
		// On ajoute la derniere annee
-
 
391
		$html .= $this->calculeCalendrierPermanent(date ('Y'));
-
 
392
		
-
 
393
		if ($this->isFichierCalendrierExiste()) {
-
 
394
			// S il existe mais qu il est trop vieux, il faut le recalculer
-
 
395
			if ($this->isDoitRecalculerCalendrier()) {
-
 
396
				$annees = $this->getAnneesARecalculer();
-
 
397
				$html .= $this->calculeCalendrierPermanent($annees);
-
 
398
		    }
-
 
399
			$html .= file_get_contents('tmp/'.$this->listname.'.calendrier');
-
 
400
		} else {
-
 
401
			$html .= $this->ecrireFichierCalendrier();
-
 
402
		}	
-
 
403
		return $html;
-
 
404
	}
-
 
405
	
-
 
406
	function isFichierCalendrierExiste() {
-
 
407
		if (file_exists('tmp/'.$this->listname.'.calendrier')) {
-
 
408
			return true;
-
 
409
		}
-
 
410
		return false;
-
 
411
	}
-
 
412
	function isDoitRecalculerCalendrier() {
-
 
413
 
-
 
414
		if (date ('Y', fileatime('tmp/'.$this->listname.'.calendrier')) != date('Y')) return true;
-
 
415
		return false;
-
 
416
	}
-
 
417
	
-
 
418
	function getAnneesARecalculer() {
-
 
419
		// On suppose que l index de ezmlm est correct
-
 
420
		$anneeFichierCalendrier = date ('Y', fileatime('tmp/'.$this->listname.'.calendrier'));
-
 
421
		return $anneeFichierCalendrier + 1;
315
	}
422
	}
-
 
423
	
316
}
424
}
317
 
425
 
318
// CLASS: ezmlm-thread is a quick little class to allow us to define
426
// CLASS: ezmlm-thread is a quick little class to allow us to define
319
// a structure of the current thread in a single-linked list.
427
// a structure of the current thread in a single-linked list.
320
// it's a little messy since php doesn't support pointers like C does
428
// it's a little messy since php doesn't support pointers like C does
321
// so we have to use references and a head object to append to the list.
429
// so we have to use references and a head object to append to the list.
322
class ezmlm_thread {
430
class ezmlm_thread {
323
	var $next;
431
	var $next;
324
	var $depth;
432
	var $depth;
325
	var $file;
433
	var $file;
326
	var $msgid;
434
	var $msgid;
327
	var $inreply;
435
	var $inreply;
328
	var $references;
436
	var $references;
329
	function append($thread) {
437
	function append($thread) {
330
		$thread_curr =& $this;
438
		$thread_curr =& $this;
331
		while ($thread_curr->next != NULL) {
439
		while ($thread_curr->next != NULL) {
332
			$thread_curr =& $thread_curr->next;
440
			$thread_curr =& $thread_curr->next;
333
		}
441
		}
334
		$thread_curr->next = $thread;
442
		$thread_curr->next = $thread;
335
	}
443
	}
336
	function &find_msgid($msgid) {
444
	function &find_msgid($msgid) {
337
		$thread_curr =& $this;
445
		$thread_curr =& $this;
338
		while ($thread_curr->next != NULL) {
446
		while ($thread_curr->next != NULL) {
339
			if (trim($thread_curr->msgid) == trim($msgid)) { return $thread_curr; }
447
			if (trim($thread_curr->msgid) == trim($msgid)) { return $thread_curr; }
340
			$thread_curr =& $thread_curr->next;
448
			$thread_curr =& $thread_curr->next;
341
		}
449
		}
342
		return NULL;
450
		return NULL;
343
	}
451
	}
344
	function ezmlm_thread($depth,$file,$msgid) {
452
	function ezmlm_thread($depth,$file,$msgid) {
345
		$this->depth = $depth;
453
		$this->depth = $depth;
346
		$this->file  = $file;
454
		$this->file  = $file;
347
		$this->msgid = $msgid;
455
		$this->msgid = $msgid;
348
		$this->next = NULL;
456
		$this->next = NULL;
349
	}
457
	}
350
}
458
}
351
?>
459
?>