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)) { |
382606fb PHM |
47 | require_once 'banana/misc.inc.php'; |
48 | $this->body = to_html($this->body, $matches[1]); | |
e785d91c | 49 | } |
1eed39ee | 50 | } |
1eed39ee | 51 | |
2dbc0167 | 52 | function _header() |
01681efd | 53 | { |
2dbc0167 | 54 | global $banana; |
b9ea5b30 | 55 | $hdrs = $banana->nntp->head($this->id); |
e785d91c | 56 | if (!$hdrs) { |
57 | $this = null; | |
58 | return false; | |
59 | } | |
01681efd | 60 | |
e785d91c | 61 | // parse headers |
62 | foreach ($hdrs as $line) { | |
63 | if (preg_match("/^[\t\r ]+/", $line)) { | |
01681efd | 64 | $line = ($hdr=="X-Face"?"":" ").ltrim($line); |
2dbc0167 | 65 | if (in_array($hdr, $banana->parse_hdr)) { |
01681efd | 66 | $this->headers[$hdr] .= $line; |
e785d91c | 67 | } |
68 | } else { | |
69 | list($hdr, $val) = split(":[ \t\r]*", $line, 2); | |
01681efd | 70 | $hdr = strtolower($hdr); |
2dbc0167 | 71 | if (in_array($hdr, $banana->parse_hdr)) { |
01681efd | 72 | $this->headers[$hdr] = $val; |
e785d91c | 73 | } |
e785d91c | 74 | } |
75 | } | |
76 | // decode headers | |
2dbc0167 | 77 | foreach ($banana->hdecode as $hdr) { |
01681efd | 78 | if (isset($this->headers[$hdr])) { |
79 | $this->headers[$hdr] = headerDecode($this->headers[$hdr]); | |
e785d91c | 80 | } |
81 | } | |
01681efd | 82 | |
83 | $this->name = $this->headers['from']; | |
84 | $this->name = preg_replace('/<[^ ]*>/', '', $this->name); | |
85 | $this->name = trim($this->name); | |
1eed39ee | 86 | } |
b9ea5b30 | 87 | |
65d96b1f | 88 | function checkcancel() |
89 | { | |
b9ea5b30 | 90 | if (function_exists('hook_checkcancel')) { |
91 | return hook_checkcancel($this->headers); | |
92 | } | |
93 | return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); | |
94 | } | |
95 | ||
65d96b1f | 96 | function to_html() |
97 | { | |
98 | global $banana; | |
99 | ||
100 | $res = '<table class="bicol banana_msg" cellpadding="0" cellspacing="0">'; | |
101 | $res .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>'; | |
102 | ||
103 | foreach ($banana->show_hdr as $hdr) { | |
104 | if (isset($this->headers[$hdr])) { | |
105 | $res2 = formatdisplayheader($hdr, $this->headers[$hdr]); | |
106 | if ($res2) { | |
107 | $res .= '<tr><td class="hdr">'.header_translate($hdr)."</td><td class='val'>$res2</td></tr>\n"; | |
108 | } | |
109 | } | |
110 | } | |
111 | ||
112 | $res .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>'; | |
113 | $res .= '<tr><td colspan="2"><pre>'.formatbody($this->body).'</pre></td></tr>'; | |
114 | ||
115 | $res .= '<tr><th colspan="2">'._b_('apercu').'</th></tr>'; | |
116 | $ndx = $banana->spool->getndx($this->id); | |
117 | $res .= '<tr><td class="thrd" colspan="2">'.$banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx).'</td></tr>'; | |
118 | ||
119 | return $res.'</table>'; | |
120 | } | |
1eed39ee | 121 | } |
122 | ||
123 | ?> |