2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
10
* +-----------------------------------------------------------------------+
12
* | W3C� SOFTWARE NOTICE AND LICENSE |
13
* | http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 |
15
* | This work (and included software, documentation such as READMEs, |
16
* | or other related items) is being provided by the copyright holders |
17
* | under the following license. By obtaining, using and/or copying |
18
* | this work, you (the licensee) agree that you have read, understood, |
19
* | and will comply with the following terms and conditions. |
21
* | Permission to copy, modify, and distribute this software and its |
22
* | documentation, with or without modification, for any purpose and |
23
* | without fee or royalty is hereby granted, provided that you include |
24
* | the following on ALL copies of the software and documentation or |
25
* | portions thereof, including modifications: |
27
* | 1. The full text of this NOTICE in a location viewable to users |
28
* | of the redistributed or derivative work. |
30
* | 2. Any pre-existing intellectual property disclaimers, notices, |
31
* | or terms and conditions. If none exist, the W3C Software Short |
32
* | Notice should be included (hypertext is preferred, text is |
33
* | permitted) within the body of any redistributed or derivative |
36
* | 3. Notice of any changes or modifications to the files, including |
37
* | the date changes were made. (We recommend you provide URIs to |
38
* | the location from which the code is derived.) |
40
* | THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT |
41
* | HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, |
42
* | INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR |
43
* | FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE |
44
* | OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, |
45
* | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. |
47
* | COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, |
48
* | SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE |
49
* | SOFTWARE OR DOCUMENTATION. |
51
* | The name and trademarks of copyright holders may NOT be used in |
52
* | advertising or publicity pertaining to the software without |
53
* | specific, written prior permission. Title to copyright in this |
54
* | software and any associated documentation will at all times |
55
* | remain with copyright holders. |
57
* +-----------------------------------------------------------------------+
62
* @author Heino H. Gehlsen <heino@gehlsen.dk>
63
* @copyright 2002-2011 Heino H. Gehlsen <heino@gehlsen.dk>. All Rights Reserved.
64
* @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 W3C� SOFTWARE NOTICE AND LICENSE
65
* @version SVN: $Id: article.php 306619 2010-12-24 12:16:07Z heino $
66
* @link http://pear.php.net/package/Net_NNTP
68
* @since File available since release 1.3.0
75
require_once 'config.inc.php';
80
require_once 'common.inc.php';
86
// Must have either $messageNum or $messageID
87
if (is_null($messageNum) and is_null($messageID)) {
88
error('Error: Nither message number nor message-id provided!');
91
// Only $messageNum OR $messageID
92
if (!is_null($messageNum) and !is_null($messageId)) {
93
error('Error: Both message-id _AND_ message number provided!');
96
// $messageNum requires $group
97
if (is_null($messageNum) and !is_null($group)) {
98
error('Error: Message number requires group!');
103
$messageID = $group === null ? $article : null;
104
#$article = $group !== null ? $article : null;
106
/* Prepare breadcrumbs */
108
$breadcrumbs = array();
109
$breadcrumbs['Frontpage'] = './index.php?' . query();
110
$breadcrumbs['groups @ ' . ($host == null ? 'localhost' : $host)] = './groups.php?' . query();
111
if ($messageID !== null) {
112
$breadcrumbs['Article: '.htmlentities($messageID)] = null;
114
$breadcrumbs['group: '.$group] = './group.php?' . query("group=$group&from=$from&next=$next");
115
$breadcrumbs['Article: #'.$article] = null;
120
$posting = $nntp->connect($host, $encryption, $port);
121
if (PEAR::isError($posting)) {
122
error('Unable to connect to NNTP server: ' . $posting->getMessage());
126
// Start TLS encryption
128
$R = $nntp->cmdStartTLS();
129
if (PEAR::isError($R)) {
130
error('Unable to connect to NNTP server: ' . $R->getMessage());
135
if (!is_null($user) && !is_null($pass)) {
136
$authenticated = $nntp->authenticate($user, $pass);
137
if (PEAR::isError($authenticated)) {
138
error('Unable to authenticate: ' . $authenticated->getMessage());
142
// If asked for a article in a group, select group then article
143
if ($messageID === null) {
146
$summary = $nntp->selectGroup($group);
147
if (PEAR::isError($summary)) {
148
error($summary->getMessage());
152
$article = $nntp->selectArticle($article);
153
if (PEAR::isError($article)) {
154
error($article->getMessage());
157
if ($article === false) {
158
error('The article is not avalible on the server!');
162
$overview = $nntp->getOverview();
163
if (PEAR::isError($overview)) {
164
$logger->warning('Error fetching overview (Server response: ' . $overview->getMessage() . ')');
170
// Fetch 'Newsgroups' header field
171
$groups = $nntp->getHeaderField('Newsgroups');
172
if (PEAR::isError($groups)) {
173
$logger->warning('Error fetching \'Newsgroups\' header field (Server response: ' . $groups->getMessage() . ')');
182
$header = $nntp->getHeader($messageID);
183
if (PEAR::isError($header)) {
184
error('Error fetching header (Server response: ', $header->getMessage(), ')');
186
if ($header === false) {
187
error('The article is not avalible on the server!');
193
$body = $nntp->getBody($messageID);
194
if (PEAR::isError($body)) {
195
error('Error fetching body (Server response: ', $body->getMessage(), ')');
209
function x($header, $fieldname, $index = 0)
212
$fieldname = strtolower($fieldname);
215
for ($i = 0, $j = 0 ; $i < count($header) ; $i++) {
221
@list($tag, $value) = explode(": ", $line, 2);
222
if (strtolower($tag) != $fieldname) {
226
// Skip if $index not reached
231
// Append folded lines...
232
while (($next = $header[++$i]) && ($next[0] == ' ' || $next[0] == "\t")) {
233
$value .= ' ' . ltrim($next, " \t");
243
if (!empty($overview)) {
244
$subject = $overview['Subject'];
245
$from = $overview['From'];
246
$date = $overview['Date'];
247
$references = $overview['References'];
250
$subject = x($header, 'Subject');
251
$from = x($header, 'From');
252
$date = x($header, 'Date');
253
$references = x($header, 'References');
255
if (empty($references)) {
256
$references = x($header, 'In-reply-to');
262
if (empty($groups)) {
263
$logger->info('Received an empty \'Newsgroups\' header field - parsing header as backup...');
264
$groups = x($header, 'Newsgroups');
269
$references = empty($references) ? null : preg_split("/[ \t]/", $references);
277
function outputHead()
282
echo '<table id="article-head" border="0" cellpadding="2" cellspacing="2" width="100%">' . "\r\n";
285
echo ' <tr>' . "\r\n";
286
echo ' <td class="label">Subject:</td>' . "\r\n";
287
echo ' <td class="value" colspan="3"><b>' . htmlspecialchars($subject) . '</b></td>', "\r\n";
288
echo ' </tr>', "\r\n";
290
echo ' <tr>', "\r\n";
291
echo ' <td class="label">From:</td>' . "\r\n";
292
echo ' <td class="value">' . htmlspecialchars($from) . '</td>', "\r\n";
294
echo ' <td class="label">Date:</td>' . "\r\n";
295
echo ' <td class="value">' . htmlspecialchars($date) . '</td>', "\r\n";
296
echo ' </tr>', "\r\n";
297
echo ' <tr>', "\r\n";
300
echo ' <td class="label">References:</td>' . "\r\n";
301
echo ' <td class="value">';
303
case is_array($references):
304
foreach ($references as $reference) {
305
echo ' <a href="article.php?', query('article='.urlencode($reference)), '">#', ++$i, '</a>', "\r\n";
308
case is_string($references) && !empty($references):
309
echo ' <a href="article.php?', query('article='.urlencode($reference)), '">#', ++$i, '</a>', "\r\n";
312
echo ' </td>', "\r\n";
316
echo ' <td class="label">Groups:</td>' . "\r\n";
317
echo ' <td class="value">', "\r\n";
318
foreach (explode(',', $groups) as $group) {
319
echo '<a href="./group.php?'. query('group='.urlencode($group)), '">', $group, '</a> ';
321
echo ' </td>', "\r\n";
322
echo ' </tr>', "\r\n";
325
echo '</table>', "\r\n";
331
function outputHeader()
336
echo '<blockquote id="article-header">', "\r\n";
337
echo ' <pre>', "\r\n";
338
echo preg_replace("/\r\n(\t| )+/", ' ', implode("\r\n", $header));
339
echo ' </pre>', "\r\n";
340
echo '</blockquote>', "\r\n";
346
function outputBody()
351
echo '<blockquote id="article-body">', "\r\n";
352
echo ' <pre>', "\r\n";
353
foreach ($body as $line) {
355
/* Code from news.php.net begins here */
357
// this is some amazingly simplistic code to color quotes/signatures
358
// differently, and turn links into real links. it actually appears
359
// to work fairly well, but could easily be made more sophistimicated.
360
$line = htmlentities($line, ENT_NOQUOTES, 'utf-8');
361
$line = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\\s|\\)|\\.\\s|$)/", "<a href=\"\\1\">\\1</a>\\3", $line);
362
if (!$insig && $line == "-- \r\n") {
363
echo '<span class="signature">';
366
if ($insig && $line == "\r\n") {
370
if (!$insig && substr($line, 0, 4) == '>') {
371
echo '<span class="quote">', $line, '</span>';
375
/* Code from news.php.net ends here */
379
echo ' </pre>', "\r\n";
380
echo '</blockquote>', "\r\n";
391
include 'header.inc.php';
401
include 'footer.inc.php';