Citation :
/*
* decodes a body. Splits the content of $body into an array of several
* lines, respecting the special decoding issues of format=flowed
* articles. Each returned line consists of two fields: text and
* the quote depth (depth)
*/
function decode_textbody($body,$format="fixed" ) {
$body=split("\n",$body);
$nbody=array();
$depth=0;
$paragraph=""; // empty paragraph
$lastline="";
for($i=0; $i<count($body)+1; $i++) {
// calculate the quote depth of the actual line
$ndepth=0;
$tdepth=0;
ligne396: for($j=0; $j<=strlen($body[$i]); $j++) {
$tdepth=$j;
if(isset($body[$i][$j])&&$body[$i][$j]=='>') {
$ndepth++;
} else {
if( isset($body[$i][$j])&& ($body[$i][$j]!=' ') || isset($body[$i][$j-1])&&($body[$i][$j-1]==' ') || ($j==0)) {
break;
}
}
}
// generate a new paragraph?
if(($i>0) && (($ndepth!=$depth) || $format!="flowed" ||
(isset($paragraph[strlen($paragraph)-1]))&&($paragraph[strlen($paragraph)-1]!=' ')) || ($i==count($body))) {
$tmp->text=$lastline=$paragraph;
$tmp->depth=$depth;
$paragraph="";
if(phpversion()>=5)
$nbody[]=clone($tmp);
else
$nbody[]=$tmp;
}
if(isset($body[$i]) && $body[$i]=="-- " && $format=="flowed" )
$body[$i]="--";
ligne419: $paragraph.=substr($body[$i],$tdepth);
$depth=$ndepth;
}
return $nbody;
}
/*
* replaces multiple spaces in texts by es and convert special-chars
* to their entities
*/
function text2html($text) {
return eregi_replace("^ "," ",
str_replace(" "," ",
str_replace(" "," ",
str_replace("\n","<br>",
htmlspecialchars($text)))));
}
/*
* print an article to the webpage
*
* $group: The name of the newsgroup
* $id: the ID of the article inside the group or the message-id
* $attachment: The number of the attachment of the article.
* 0 means the normal textbody.
*/
function message_show($group,$id,$attachment=0,$article_data=false,$maxlen=false) {
global $file_article,$file_article_full;
global $text_header,$text_article,$article_showthread;
global $block_xnoarchive,$article_graphicquotes;
if ($article_data == false)
$article_data=message_read($id,$attachment,$group);
$head=$article_data->header;
$body=$article_data->body[$attachment];
if ($head) {
if (($block_xnoarchive) && (isset($head->xnoarchive)) &&
($head->xnoarchive=="yes" )) {
echo $text_article["block-xnoarchive"];
} else
if (($head->content_type[$attachment]=="text/plain" ) &&
($attachment==0)) {
show_header($head,$group);
$body=decode_textbody($body,
$article_data->header->content_type_format[$attachment]);
$depth=0;
echo '<div class="np_article_body">';
$currentlen=0; // needed if $maxlen is set
for ($i=0; $i<=count($body) &&
(($currentlen<$maxlen) || ($maxlen==false)); $i++) {
// HTMLized Quotings instead of boring > ?
if($article_graphicquotes) {
// HTMLized Quotings
ligne472: for($j=$depth; $j<$body[$i]->depth; $j++)
echo '<blockquote class="np_article_quote">';
ligne474: for($j=$body[$i]->depth; $j<$depth; $j++)
echo '</blockquote>';
ligne476: $t=html_parse(text2html($body[$i]->text)).'<br>';
echo $t;
$currentlen+=strlen($t);
echo "\n";
ligne480: $depth=$body[$i]->depth;
} else {
// Boring old Quotings with >
if($body[$i]->depth==0) {
if(trim($body[$i]->text)=='')
$t="<br>\n";
else
$t=html_parse(text2html($body[$i]->text))."<br>\n";
} else {
$t='<i>'.str_repeat('>',$body[$i]->depth).' '.
html_parse(text2html(
textwrap($body[$i]->text,72-$body[$i]->depth,
"\n".str_repeat('>',$body[$i]->depth).' '))).
"</i><br>\n";
}
echo $t;
$currentlen+=strlen($t);
}
}
echo '</div>';
if($maxlen!=false && $currentlen>=$maxlen) {
echo '<br><a href="'.$file_article_full.'?id='.$id.'&group='.
$group.'">'.$text_article["full_article"].'</a>';
}
} else {
echo $body;
}
}
}
|