Subversion Repositories Applications.projet

Rev

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

Rev Author Line No. Line
2 ddelon 1
<?php
405 raphael 2
// $Id: ezmlm.php,v 1.3.2.2 2007/03/13 11:04:46 alexandre_tb Exp $
2 ddelon 3
//
4
// ezmlm.php - ezmlm-php v2.0
5
// --------------------------------------------------------------
6
// As the site that ezmlm-php was developed for grew, and grew
7
// the old system used had to be bandaid fixed more, and more
8
// because the site started moving to an object oriented design
9
// for all the backend systems and ezmlm wasn't playing nice
10
// with the new design. So, ezmlm was redesigned too, and here
11
// it is.
12
//
13
// It may look a little more confusing if you're not used to
14
// working with objects but it actually is much more effiecient
15
// and organized in it's new incarnation.
16
// Simply edit the variables in the ezmlm-php constructor below
17
// just like you would with the old ezmlm-php-config.php file,
18
// if you're unsure howto do this check out the file CONFIG,
19
// then check the USAGE file for how you should include and use
20
// the new classes if you are integrating ezmlm-php into your
21
// site.
22
// (SEARCH FOR: USER-CONFIG to find where to edit.)
23
// --------------------------------------------------------------
24
 
25
require_once("ezmlm-errors.def");
26
require_once("ezmlm-parser.php");
27
require_once("ezmlm-threads.php");
28
require_once("ezmlm-listinfo.php");
29
require_once("ezmlm-msgdisplay.php");
30
require_once("ezmlm-repondre.php");
31
require_once("ezmlm-author.php");
32
 
405 raphael 33
$GLOBALS['mois'] = array ('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre') ;
2 ddelon 34
 
35
// CLASS: ezmlm_php
36
// the base class, contains common functions and the config
37
class ezmlm_php {
38
	var $listdir;		// the root directory of the list
39
	var $listname;		// the list address upto the @
40
	var $listdomain;	// the domain for the list
41
 
42
	var $tempdir;		// a directory in which the webserver can write cache files
43
 
44
	var $sendheaders;	// send generic page headers
45
	var $sendbody;		// send generic body definitions
46
	var $sendfooters;	// send generic page footers
47
	var $includebefore;	// a file to include before the content
48
	var $includeafter;	// a file to include after the content
49
 
50
	var $href;		// what to add before the '?param=value' in links
51
 
52
	var $prefertype;	// what mime type do you prefer?
53
	var $showheaders;	// what headers should we show?
54
 
55
	var $msgtemplate;	// the template for displaying messages (see the file TEMPLATE)
56
 
57
	var $tablecolours;	// what are the colours for the table rows?
58
 
59
	var $thread_subjlen;	// the maximum length of subjects in the thread view (0 = no limit)
60
 
61
	var $forcehref;		// force the base of makelink();
62
 
63
	// --------- END USER CONFIGURATION ---------
64
 
65
	// Internal variables
66
	var $action = '';
67
	var $actionargs;
68
 
69
	function ezmlm_php() {
423 jpm 70
 
2 ddelon 71
		// USER-CONFIG section
72
		// these variables act the same way ezmlm-php-config.php did in the first release
73
		// simply edit these variables to match your setup
423 jpm 74
 
208 neiluj 75
		$this->listdir		= "";
76
		$this->listname		= "";
77
		$this->listdomain	= "";
423 jpm 78
 
208 neiluj 79
		$this->tempdir		= "";
2 ddelon 80
 
81
		$this->sendheaders	= TRUE;
82
		$this->sendbody		= TRUE;
83
		$this->sendfooters	= TRUE;
84
		$this->includebefore	= "";
85
		$this->includeafter	= "";
86
 
87
		$this->href		= "";
88
 
89
		$this->prefertype	= "text/html";
90
		$this->showheaders	= array(
91
						"to",
92
						"from",
93
						"subject",
94
						"date"
95
					);
423 jpm 96
        $this->header_en_francais = array ('to' => 'A',
2 ddelon 97
                                            'from' => 'De',
98
                                            'subject' => 'Sujet',
99
                                            'date' => 'Date') ;
100
 
101
		$this->msgtemplate	= "<pre><ezmlm-body></pre>"; // if blank it will use the internal one
102
 
103
		$this->tablecolours	= array(
104
						// delete the next line if you don't want alternating colours
105
						"#eeeeee",
106
						"#ffffff"
107
					);
108
 
109
		$this->thread_subjlen	= 55;
110
 
111
		// --- STOP EDITING HERE ---
112
		// some sanity checking
113
		if ((!is_dir($this->listdir . "/archive")) or
114
		    (!is_dir($this->listdir . "/archive/authors")) or
115
		    (!is_dir($this->listdir . "/archive/threads")) or
116
		    (!is_dir($this->listdir . "/archive/subjects"))) {
117
            return false ;
118
			/*$this->error(EZMLM_INVALID_DIR,TRUE);*/
119
		}
120
	}
405 raphael 121
	/*
122
	 * Renvoi le nombre de message dans une archive
423 jpm 123
	 * Le nombre contenu dans liste/num
405 raphael 124
	 */
125
	function getNumArchive() {
126
		if ($this->listdir != '') {
127
			$num = split(':', file_get_contents($this->listdir.'/num'));
128
			return $num[0];
129
		}
130
	}
2 ddelon 131
 
132
	function set_action($action) {
133
		if (is_array($action)) { $this->error(EZMLM_INVALID_SYNTAX,TRUE); }
134
		$this->action = $action;
135
	}
136
	function set_actionargs($actionargs) {
137
		if ($this->action == '') { $this->error(EZMLM_INVALID_SYNTAX,TRUE); }
138
		$this->actionargs = $actionargs;
139
	}
140
 
141
	function run() {
142
		if ($this->action == '') { $this->error(EZMLM_INVALID_SYNTAX,TRUE); }
143
 
144
		if ($this->sendheaders) { $this->sendheaders(); }
145
		if ($this->sendbody) { $this->sendbody(); }
146
		if ($this->includebefore != '') { @include_once($this->includebefore); }
147
 
148
		switch ($this->action) {
149
			case "list_info":
150
				$info = new ezmlm_listinfo();
151
				$info->display();
152
				break;
153
			case "show_msg":
154
				if (count($this->actionargs) < 2) {
155
					$this->error(EZMLM_INVALID_SYNTAX,TRUE);
156
				}
157
				$show_msg = new ezmlm_msgdisplay();
158
				$show_msg->display($this->actionargs[0] . "/" . $this->actionargs[1]);
159
				break;
160
			case "show_threads":
161
				$threads = new ezmlm_threads();
162
				$threads->load($this->actionargs[0]);
163
				break;
164
			case "show_author_msgs":
165
				$author = new ezmlm_author();
166
				$author->display($this->actionargs[0]);
167
				break;
168
		}
169
 
170
		if ($this->includeafter != '') { @include_once($this->includeafter); }
171
		if ($this->sendfooters) { $this->sendfooters(); }
172
	}
173
 
174
	function sendheaders() {
175
		print "<html><head>\n";
176
		print "<style type=\"text/css\">\n";
177
		print "<!--\n";
178
		print ".heading { font-family: helvetica; font-size: 16px; line-height: 18px; font-weight: bold; }\n";
179
		print "//-->\n";
180
		print "</style>\n";
181
		print "</head>\n";
182
	}
183
 
184
	function sendbody() {
185
		print "<body>\n";
186
	}
187
 
188
	function sendfooters() {
189
		print "</body>\n";
190
		print "</html>\n";
191
	}
192
 
423 jpm 193
 
2 ddelon 194
	// begin common functions
195
 
196
	// makehash - generates an author hash using the included makehash program
197
	function makehash($str) {
198
         $str = preg_replace ('/>/', '', $str) ;
199
        $handle = popen ('/usr/local/lib/safe_mode/makehash \''.$str.'\'', 'r') ;
200
        $hash = fread ($handle, 256) ;
201
        pclose ($handle) ;
202
		return $hash;
203
	}
204
 
205
	// makelink - writes the <a href=".."> tag
206
	function makelink($params,$text) {
207
		if ($this->forcehref != "") {
208
			$basehref = $this->forcehref;
209
		} else {
210
			$basehref = preg_replace('/^(.*)\?.*/', '\\1', $_SERVER['REQUEST_URI']);
211
		}
212
		$link = '<a href="'. $basehref . '&amp;' . $params . '">' . $text . '</a>';
213
		return $link;
214
	}
215
 
216
	// md5_of_file - provides wrapper function that emulates md5_file for PHP < 4.2.0
217
	function md5_of_file($file) {
218
		if (function_exists("md5_file")) { // php >= 4.2.0
219
			return md5_file($file);
220
		} else {
221
			if (is_file($file)) {
222
				$fd = fopen($file, "rb");
223
				$filecontents = fread($fd, filesize($file));
224
				fclose ($fd);
225
				return md5($filecontents);
226
			} else {
227
				return FALSE;
228
			}
229
		}
230
	}
231
 
232
	// protect_email - protects email address turns user@domain.com into user@d...
233
	function protect_email($str,$short = FALSE) {
234
		if (preg_match("/[a-zA-Z0-9\-\.]\@[a-zA-Z0-9\-\.]*\./", $str)) {
235
			$outstr = preg_replace("/([a-zA-Z0-9\-\.]*\@)([a-zA-Z0-9\-\.])[a-zA-Z0-9\-\.]*\.[a-zA-Z0-9\-\.]*/","\\1\\2...",$str);
236
			$outstr = preg_replace("/\</", '&lt;', $outstr);
237
			$outstr = preg_replace("/\>/", '&gt;', $outstr);
238
		} else {
239
			$outstr = $str;
240
		}
241
 
242
		if ($short) {
243
			$outstr = preg_replace("/&lt;.*&gt;/", '', $outstr);
244
			$outstr = preg_replace("/[\"']/", '', $outstr);
245
		}
405 raphael 246
 
395 aurelien 247
		$at_split = explode('@',$outstr);
248
		$outstr = $at_split[0];
394 aurelien 249
 
250
		$points_sep = explode('.',$outstr);
251
		if(count($points_sep) > 2) {
252
			$outstr = implode('.', array_slice($points_sep,0,count($points_sep) - 2));
253
			$outstr = rtrim($outstr, '.').'...';
254
		}
2 ddelon 255
		return trim($outstr);
256
	}
257
 
258
	// cleanup_body: sortta like protect_email, just for message bodies
259
	function cleanup_body($str) {
260
			$outstr = preg_replace("/([a-zA-Z0-9\-\.]*\@)([a-zA-Z0-9\-\.])[a-zA-Z0-9\-\.]*\.[a-zA-Z0-9\-\.]*/","\\1\\2...",$str);
261
			return $outstr;
262
	}
263
 
264
	function error($def, $critical = FALSE) {
265
		global $ezmlm_error;
266
 
267
		print "\n\n";
268
		print "<table width=600 border=1 cellpadding=3 cellspacing=0>\n";
269
		print "<tr bgcolor=\"#cccccc\"><td><b>EZMLM-PHP Error: " . $ezmlm_error[$def]['title'] . "</td></tr>\n";
270
		print "<tr bgcolor=\"#aaaaaa\"><td>" . $ezmlm_error[$def]['body'] . "</td></tr>\n";
271
		print "</table>\n\n";
272
 
273
		if ($critical) { die; }
274
	}
275
    /**
405 raphael 276
     *  Parse une chaine et supprime les probleme d'encodage de type ISO-4 ...
2 ddelon 277
     *
278
     * @return string
279
     */
423 jpm 280
 
2 ddelon 281
    function decode_iso ($chaine) {
423 jpm 282
 
2 ddelon 283
        if (preg_match ('/windows-[0-9][0-9][0-9][0-9]/i', $chaine, $nombre)) {
284
            $reg_exp = $nombre[0] ;
208 neiluj 285
            $chaine = str_replace(' ', '', $chaine);
2 ddelon 286
        } else {
287
            $reg_exp = 'ISO-8859-15?' ;
288
        }
289
        if (preg_match ('/UTF/i', $chaine)) $reg_exp = 'UTF-8' ;
290
        preg_match_all ("/=\?$reg_exp\?(Q|B)\?(.*?)\?=/i", $chaine, $match, PREG_PATTERN_ORDER)  ;
291
        for ($i = 0; $i < count ($match[0]); $i++ ) {
423 jpm 292
 
165 alexandre_ 293
                if (strtoupper($match[1][$i]) == 'Q') {
2 ddelon 294
                    $decode = quoted_printable_decode ($match[2][$i]) ;
295
                } elseif ($match[1][$i] == 'B') {
296
                    $decode = base64_decode ($match[2][$i]) ;
297
                }
298
                $decode = preg_replace ("/_/", " ", $decode) ;
299
            if ($reg_exp == 'UTF-8') {
300
                $decode = utf8_decode ($decode) ;
423 jpm 301
            }
2 ddelon 302
            $chaine = str_replace ($match[0][$i], $decode, $chaine) ;
303
        }
304
        return $chaine ;
305
    }
423 jpm 306
 
2 ddelon 307
    /**
308
     *
309
     *
310
     * @return
311
     */
423 jpm 312
 
2 ddelon 313
    function date_francaise ($date_mail) {
405 raphael 314
        $date_mail = preg_replace ('/CEST/', '', $date_mail) ;
2 ddelon 315
        $numero_mois = date('m ', strtotime($date_mail)) - 1 ;
316
        $date = date ('d ', strtotime($date_mail)).$GLOBALS['mois'][$numero_mois] ; // Le jour et le mois
405 raphael 317
        $date .= date(' Y ', strtotime($date_mail)) ; // l'annee
2 ddelon 318
        if (date('a', strtotime($date_mail)) == 'pm') {
319
            $date .= (int) date('g', strtotime($date_mail)) + 12 ;  // Les heures
320
        } else {
321
            $date .= date('g', strtotime($date_mail)) ;
322
        }
323
        $date .= date(':i', strtotime($date_mail)) ;    // Les minutes
324
        return $date ;
325
    }
423 jpm 326
 
327
    /**
208 neiluj 328
     * Cette fonction renvoie le prefixe, cad 0 ou rien
329
     * d un nom de message, ex : pour 09, on renvoie 0
330
     * pour 12 on renvoie rien
331
     */
332
    function prefixe_nom_message($nom) {
333
    	if (preg_match ('/0([1-9][0-9]*)/', $nom, $match)) {
334
			$nom_fichier = $match[1];
335
			return '0' ;
336
		} else {
337
			return '' ;
338
		}
339
    }
2 ddelon 340
}
341
 
342
//
343
// --- END OF CLASS DEFINITION ---
344
//
345
 
346
// FIN