From f59f8188332cccb02edea6dc81e8ef3d8279dccd Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Sat, 2 Sep 2023 07:38:59 -0700 Subject: [PATCH] Display links in body. Not as easy as it sounds. --- Rocksolid_Light/rocksolid/lib/message.inc.php | 2 +- Rocksolid_Light/rocksolid/newsportal.php | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Rocksolid_Light/rocksolid/lib/message.inc.php b/Rocksolid_Light/rocksolid/lib/message.inc.php index 486453e..e1189e7 100644 --- a/Rocksolid_Light/rocksolid/lib/message.inc.php +++ b/Rocksolid_Light/rocksolid/lib/message.inc.php @@ -702,7 +702,7 @@ function message_show($group,$id,$attachment=0,$article_data=false,$maxlen=false for($j=@$body[$i]->depth; $j<$depth; $j++) echo ''; $t = @$body[$i]->text; - echo $t; + echo display_links_in_body($t); $currentlen+=strlen($t); echo "\n"; $depth=@$body[$i]->depth; diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index fe0b200..31ce5ae 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -995,32 +995,35 @@ function html_parse($text) $is_link = 0; for ($i = 0; $i < $n; $i ++) { $word = $words[$i]; - if (preg_match('/(https?|ftp|news|gopher|telnet)\:\/\/[^\",]+/i', $word)) { - $is_link = 1; - $nlink = trim($word, '().,'); - $nlink = preg_replace('/(\<|\>|\ );/', '', $nlink); - $nlink = preg_replace('/\[url=/', '', $nlink); - $bbnlink = explode(']', $nlink); - $nlink = $bbnlink[0]; - $nword = '' . $nlink . ''; - if (isset($bbnlink[1])) { - $nword .= ' ' . $bbnlink[1]; - } - if ($nword != $word && substr($nlink, strlen($nlink) - 3) != "://") { - $word = $nword; - } - } // add the spaces between the words if ($i > 0) $ntext .= " "; - if ($is_link) { - $word = preg_replace('/\[\/url\]/', '', $word); - } $ntext .= $word; } 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, '' . $url . '', $text, 1); + } + echo $text; +} + /* * read the header of an article in plaintext into an array * $articleNumber can be the number of an article or its message-id.