Display links in body. Not as easy as it sounds.

This commit is contained in:
Retro_Guy 2023-09-02 07:38:59 -07:00
parent f8ab6c54f0
commit f59f818833
2 changed files with 22 additions and 19 deletions

View File

@ -702,7 +702,7 @@ function message_show($group,$id,$attachment=0,$article_data=false,$maxlen=false
for($j=@$body[$i]->depth; $j<$depth; $j++) for($j=@$body[$i]->depth; $j<$depth; $j++)
echo '</blockquote>'; echo '</blockquote>';
$t = @$body[$i]->text; $t = @$body[$i]->text;
echo $t; echo display_links_in_body($t);
$currentlen+=strlen($t); $currentlen+=strlen($t);
echo "\n"; echo "\n";
$depth=@$body[$i]->depth; $depth=@$body[$i]->depth;

View File

@ -995,32 +995,35 @@ function html_parse($text)
$is_link = 0; $is_link = 0;
for ($i = 0; $i < $n; $i ++) { for ($i = 0; $i < $n; $i ++) {
$word = $words[$i]; $word = $words[$i];
if (preg_match('/(https?|ftp|news|gopher|telnet)\:\/\/[^\",]+/i', $word)) {
$is_link = 1;
$nlink = trim($word, '().,');
$nlink = preg_replace('/(\&lt|\&gt|\&nbsp);/', '', $nlink);
$nlink = preg_replace('/\[url=/', '', $nlink);
$bbnlink = explode(']', $nlink);
$nlink = $bbnlink[0];
$nword = '<a ' . $target . ' href="' . $nlink . '">' . $nlink . '</a>';
if (isset($bbnlink[1])) {
$nword .= ' ' . $bbnlink[1];
}
if ($nword != $word && substr($nlink, strlen($nlink) - 3) != "://") {
$word = $nword;
}
}
// add the spaces between the words // add the spaces between the words
if ($i > 0) if ($i > 0)
$ntext .= " "; $ntext .= " ";
if ($is_link) {
$word = preg_replace('/\[\/url\]/', '', $word);
}
$ntext .= $word; $ntext .= $word;
} }
return ($ntext); return ($ntext);
} }
function display_links_in_body($text)
{
preg_match_all('/(https?|ftp|scp|news|gopher|telnet):\/\/[a-zA-Z0-9.?%=\-\+\;\:\~\@\!\#&_\/]+/', $text, $matches);
$found = array();
foreach ($matches[0] as $match) {
if (! $match) {
continue;
}
if (in_array($match, $found)) {
continue;
}
$found[] = $match;
$linkurl = preg_replace("/(<|>)/", ' ', htmlspecialchars_decode($match));
$url = preg_replace("/(<|>)/", ' ', $match);
$pattern = preg_quote($url);
$pattern = "!$pattern!";
$text = preg_replace($pattern, '<a href="' . $linkurl . '" rel="nofollow" target="_blank">' . $url . '</a>', $text, 1);
}
echo $text;
}
/* /*
* read the header of an article in plaintext into an array * read the header of an article in plaintext into an array
* $articleNumber can be the number of an article or its message-id. * $articleNumber can be the number of an article or its message-id.