Subversion Repositories Applications.projet

Rev

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

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