Subversion Repositories Applications.projet

Rev

Rev 208 | Rev 359 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 208 Rev 308
Line 1... Line 1...
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
Line 250... Line 250...
250
		return TRUE;
250
		return TRUE;
251
	}
251
	}
Line 252... Line 252...
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
        }
-
 
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;
262
        }
272
        /*
Line 263... Line 273...
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))) {
Line 268... Line 278...
268
			// $item contient les noms des repertoires
278
			// $item contient les noms des repertoires
Line 278... Line 288...
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
}
Line 317... Line 425...
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.