Commit | Line | Data |
---|---|---|
1eed39ee | 1 | <?php |
1eed39ee | 2 | /******************************************************************************** |
3 | * include/posts.inc.php : class for posts | |
4 | * ----------------------- | |
5 | * | |
6 | * This file is part of the banana distribution | |
7 | * Copyright: See COPYING files that comes with this distribution | |
8 | ********************************************************************************/ | |
9 | ||
10 | /** class for posts | |
11 | */ | |
12 | ||
d4c19591 | 13 | class BananaPost |
14 | { | |
b9ea5b30 | 15 | var $id; |
e785d91c | 16 | /** headers */ |
17 | var $headers; | |
18 | /** body */ | |
19 | var $body; | |
01681efd | 20 | /** poster name */ |
21 | var $name; | |
1eed39ee | 22 | |
e785d91c | 23 | /** constructor |
e785d91c | 24 | * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case) |
25 | */ | |
2dbc0167 | 26 | function BananaPost($_id) |
d4c19591 | 27 | { |
2dbc0167 | 28 | global $banana; |
b9ea5b30 | 29 | $this->id = $_id; |
2dbc0167 | 30 | $this->_header(); |
01681efd | 31 | |
8d99c683 | 32 | if ($body = $banana->nntp->body($_id)) { |
33 | $this->body = join("\n", $body); | |
34 | } else { | |
35 | return ($this = null); | |
36 | } | |
01681efd | 37 | |
38 | if (isset($this->headers['content-transfer-encoding'])) { | |
39 | if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) { | |
40 | $this->body = base64_decode($this->body); | |
41 | } elseif (preg_match("/quoted-printable/", $this->headers['content-transfer-encoding'])) { | |
42 | $this->body = quoted_printable_decode($this->body); | |
43 | } | |
e785d91c | 44 | } |
01681efd | 45 | |
1248ebac | 46 | if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) { |
25466d0e | 47 | $this->body = iconv($matches[1], 'utf-8', $this->body); |
c42efe2f PHM |
48 | } else { |
49 | $this->body = utf8_encode($this->body); | |
e785d91c | 50 | } |
1eed39ee | 51 | } |
1eed39ee | 52 | |
2dbc0167 | 53 | function _header() |
01681efd | 54 | { |
2dbc0167 | 55 | global $banana; |
b9ea5b30 | 56 | $hdrs = $banana->nntp->head($this->id); |
e785d91c | 57 | if (!$hdrs) { |
58 | $this = null; | |
59 | return false; | |
60 | } | |
01681efd | 61 | |
e785d91c | 62 | // parse headers |
63 | foreach ($hdrs as $line) { | |
64 | if (preg_match("/^[\t\r ]+/", $line)) { | |
01681efd | 65 | $line = ($hdr=="X-Face"?"":" ").ltrim($line); |
2dbc0167 | 66 | if (in_array($hdr, $banana->parse_hdr)) { |
01681efd | 67 | $this->headers[$hdr] .= $line; |
e785d91c | 68 | } |
69 | } else { | |
70 | list($hdr, $val) = split(":[ \t\r]*", $line, 2); | |
01681efd | 71 | $hdr = strtolower($hdr); |
2dbc0167 | 72 | if (in_array($hdr, $banana->parse_hdr)) { |
01681efd | 73 | $this->headers[$hdr] = $val; |
e785d91c | 74 | } |
e785d91c | 75 | } |
76 | } | |
77 | // decode headers | |
2dbc0167 | 78 | foreach ($banana->hdecode as $hdr) { |
01681efd | 79 | if (isset($this->headers[$hdr])) { |
80 | $this->headers[$hdr] = headerDecode($this->headers[$hdr]); | |
e785d91c | 81 | } |
82 | } | |
01681efd | 83 | |
84 | $this->name = $this->headers['from']; | |
85 | $this->name = preg_replace('/<[^ ]*>/', '', $this->name); | |
86 | $this->name = trim($this->name); | |
1eed39ee | 87 | } |
b9ea5b30 | 88 | |
65d96b1f | 89 | function checkcancel() |
90 | { | |
b9ea5b30 | 91 | if (function_exists('hook_checkcancel')) { |
92 | return hook_checkcancel($this->headers); | |
93 | } | |
94 | return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); | |
95 | } | |
96 | ||
65d96b1f | 97 | function to_html() |
98 | { | |
99 | global $banana; | |
100 | ||
101 | $res = '<table class="bicol banana_msg" cellpadding="0" cellspacing="0">'; | |
102 | $res .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>'; | |
103 | ||
104 | foreach ($banana->show_hdr as $hdr) { | |
105 | if (isset($this->headers[$hdr])) { | |
106 | $res2 = formatdisplayheader($hdr, $this->headers[$hdr]); | |
107 | if ($res2) { | |
108 | $res .= '<tr><td class="hdr">'.header_translate($hdr)."</td><td class='val'>$res2</td></tr>\n"; | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
113 | $res .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>'; | |
114 | $res .= '<tr><td colspan="2"><pre>'.formatbody($this->body).'</pre></td></tr>'; | |
115 | ||
116 | $res .= '<tr><th colspan="2">'._b_('apercu').'</th></tr>'; | |
117 | $ndx = $banana->spool->getndx($this->id); | |
118 | $res .= '<tr><td class="thrd" colspan="2">'.$banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx).'</td></tr>'; | |
119 | ||
120 | return $res.'</table>'; | |
121 | } | |
1eed39ee | 122 | } |
123 | ||
124 | ?> |