Author Topic: problem/bug with BBcode URL  (Read 6881 times)

0 Members and 1 Guest are viewing this topic.

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
problem/bug with BBcode URL
« on: July 11, 2006, 07:57:15 PM »
Hello.

I'm having a problem with the BBcode. I'm trying to make a link like this
Code: [Select]
[url=http://nokia.com]http://www.nokia.com/6230i[/url]
But 4images does not even look at the URL= http://nokia.com it just keeps using nokia.com/6230i as the link even thoe the url should be nokia

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: problem/bug with BBcode URL
« Reply #1 on: July 12, 2006, 01:22:34 AM »
yes, I've seen this before...I'll add it to the list for v1.7.3
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: problem/bug with BBcode URL
« Reply #2 on: July 12, 2006, 01:23:40 AM »
great, you do not have any work around atm?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: problem/bug with BBcode URL
« Reply #3 on: July 12, 2006, 02:05:08 AM »
Ok, here is a quick solution (borrowed from SMF code :oops:)
in includes/functions.php find:
Code: [Select]
function replace_url($text) {
  $text = " ".$text." ";
  $url_search_array = array(
    "#([^]_a-z0-9-=\"'\/])([a-z]+?)://([^, \(\)<>\n\r]+)#si",
    "#([^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \(\)<>\n\r]*)?)#si"
  );

  $url_replace_array = array(
    "\\1<a href=\"\\2://\\3\" target=\"_blank\" rel=\"nofollow\">\\2://\\3</a>",
    "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\" rel=\"nofollow\">www.\\2.\\3\\4</a>"
  );
  $text = preg_replace($url_search_array, $url_replace_array, $text);

  if (strpos($text, "@")) {
    $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text);
  }
  return substr($text, 1, -1);
}
Replace with:
Code: [Select]
function replace_url($text) {
  $text = strtr($text, array('&#039;' => '\'', '&nbsp;' => '\xA0', '&quot;' => '>">', '"' => '<"<', '&lt;' => '<lt<'));
  $text = preg_replace(array('~(?<=[\s>\.(;\'"])((?:http|https|ftp|ftps)://[\w\-_@:|]+(?:\.[\w\-_]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\']*|\([\w\-_\~%\.@,\?&;=#()+:\']*)*[/\w\-_\~%@\?;=#])~i', '~(?<=[\s>(\'])(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\']*|\([\w\-_\~%\.@,\?&;=#()+:\']*)*[/\w\-_\~%@\?;=#])~i'), array('[url]$1[/url]', '[url=http://$1]$1[/url]'), $text);
  $text = strtr($text, array('\'' => '&#039;', '\xA0' => '&nbsp;', '>">' => '&quot;', '<"<' => '"', '<lt<' => '&lt;'));

  if (strpos($text, "@")) {
    $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text);
  }
  return $text;
}

Then find:
Code: [Select]
  if ($html !== 2) {
    $text = nl2br(trim($text));
    $text = replace_url($text);
  }
Move these four lines above
Code: [Select]
  if ($bbcode == 1) {
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: problem/bug with BBcode URL
« Reply #4 on: July 12, 2006, 11:34:36 AM »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: problem/bug with BBcode URL
« Reply #5 on: July 12, 2006, 03:11:53 PM »
Then find:
Code: [Select]
  if ($html !== 2) {
    $text = nl2br(trim($text));
    $text = replace_url($text);
  }
Move these four lines above
Code: [Select]
  if ($bbcode == 1) {
did you missed that step or maybe you copied instead of moving it?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: problem/bug with BBcode URL
« Reply #6 on: July 12, 2006, 03:51:51 PM »
I did that
Code: [Select]
  if ($html == 0 || $html == 2) {
        $text = safe_htmlspecialchars($text);
  }
  if ($html !== 2) {
  $text = nl2br(trim($text));
$text = replace_url($text);
  }

  if ($bbcode == 1) {
    $search_array = array(

But the problem is not in comments, only if I use it in details

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: problem/bug with BBcode URL
« Reply #7 on: July 13, 2006, 01:28:52 AM »
Ok, lets start from the beginning.
1) Where exactly is the problem?
2) can you use BBCode there? If not, then maybe by using this 4 lines instead would solve the problem:
Code: [Select]
  if ($html !== 2 && $bbcode == 1) {
    $text = nl2br(trim($text));
    $text = replace_url($text);
  }
(basicaly it will not auto convert urls into links if bbcode is not enabled for that particular text)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: problem/bug with BBcode URL
« Reply #8 on: July 13, 2006, 11:14:29 AM »
arg my bad :/ I was pretty sure bbcode worked in description. [stupid me]