hi guys, I like to make a url clickable inside of a tags. Can someone help me? Thank you This is my includes/bbcode.php file: http://amadoras1.do.sapo.pt/bbcode.txt Code (markup):
I tried this: Find: // [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts. $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); PHP: Replace: // [code] and [/code] for posting code (HTML, PHP, C etc etc) in your posts. //$text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); PHP: But appears like that: http://i38.tinypic.com/v33io8.jpg Now only need to make the url clickable... If I put the url without the tags appears fine, but with tags and with the modification above, appears like I show in the link above. Can you make only the url clickable inside the code tag? Please?
It will probably require a modification to the function "bbencode_first_pass_pda()". Somewhere within it, there should be a function or scripting that parses out URLs, or it will need to have <a> tags added around URL links within it.
Thank you for your reply! Can you help me? I also tried this: FIND: $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); PHP: AFTER ADD: $text.= preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text); PHP: But didn't work... any suggestion?
function autolink($message) { $text = " " . $message; $text = preg_replace("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $text); $text = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $text); $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text); $text = substr($text, 1); return($text); } PHP: What this will do is take the input, being $message, and return the properly formatted URLs that you're looking for. This function can be applied like so: (Test this first): FIND: $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); PHP: ADD AFTER: $text = autolink($text); PHP: If that function is in the phpBB2 script, it should work properly. If not, the above function will have to be added within the page somewhere. Hope this helps! -------- Edit: For some reason my explination on why you're attempted solution didn't work, but it was deleted somehow. If you want to know why it didn't, feel free to ask.
thank you so much for trying to help me! I did the changes that you suggest, but both didn't work ;( First, I added the line: $text = autolink($text); PHP: And when I post something, I got this error: Fatal error: Call to undefined function autolink() in /home/only/public_html/includes/bbcode.php on line 252 Code (markup): Before that line, I also added: function autolink($message) { $text = " " . $message; $text = preg_replace("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $text); $text = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $text); $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text); $text = substr($text, 1); return($text); } PHP: Like that: // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. $text = bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); function autolink($message) { $text = " " . $message; $text = preg_replace("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $text); $text = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $text); $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text); $text = substr($text, 1); return($text); } $text = autolink($text); PHP: Didn't work also... But I found an interesting difference... This is the post edit before the change: http://i34.tinypic.com/217f5s.jpg And this is the post edit after the change: http://i38.tinypic.com/2m4c9bd.jpg Appears that the url between code tags continues untouchable
Alright, finally figured it out! This should work as intended! ^_^ function bbencode_second_pass_code($text, $uid, $bbcode_tpl) { global $lang; $code_start_html = $bbcode_tpl['code_open']; $code_end_html = $bbcode_tpl['code_close']; // First, do all the 1st-level matches. These need an htmlspecialchars() run, // so they have to be handled differently. $match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches); for ($i = 0; $i < $match_count; $i++) { $before_replace = $matches[1][$i]; $after_replace = $matches[1][$i]; // Replace 2 spaces with " " so non-tabbed code indents without making huge long lines. $after_replace = str_replace(" ", " ", $after_replace); // now Replace 2 spaces with " " to catch odd #s of spaces. $after_replace = str_replace(" ", " ", $after_replace); // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. $after_replace = str_replace("\t", " ", $after_replace); // now Replace space occurring at the beginning of a line $after_replace = preg_replace("/^ {1}/m", ' ', $after_replace); $str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]"; $replacement = $code_start_html; $replacement .= $after_replace; $replacement .= $code_end_html; $text = str_replace($str_to_match, $replacement, $text); } // Now, do all the non-first-level matches. These are simple. $text = str_replace("[code:$uid]", $code_start_html, $text); $text = str_replace("[/code:$uid]", $code_end_html, $text); // Joel Larson (CodedCaffeine) // Modification for clickable links in code block. $text = make_clickable($text); return $text; } // bbencode_second_pass_code() PHP: Replace the "bbencode_second_pass_code()" function (all of it) with what is above. Everything else we did before should be reverted back to the original code. (before I helped.. haha)
hmmm sorry to tell you mate, but didn't work hehe Cant find any difference with that code. Is the code right?
Well then.. It should have been right. >.< I added this in: // Joel Larson (CodedCaffeine) // Modification for clickable links in code block. $text = make_clickable($text); PHP: "make_clickable()" was defined just below it, and does what you wanted. So I figured if it was added into the second pass of text, it would solve the problem because it would make the links clickable after doing the html entities stripping. I'll setup a phpBB2 forum later tonight and see if I can get some working code.
I've uploaded a working file that does the URL replacements.. I also had to upload it due to the source being messed up because of the forum editor D:
Thank you so much, Is almost perfect! Look how is showing... Post content: http://i37.tinypic.com/2m6ogw9.jpg Post view: http://i38.tinypic.com/fz28o3.jpg The url out side of code tags appears like that: http://www.nukecops.com" target="_blank">http://www.nukecops.com Code (markup): Btw, that bbcode.php file is from phpBB 2.0.23? (last version)
Yeah, it's the latest version. I just downloaded and installed it a few hours ago. I'm looking into the issue you're having.
Alright, it's now fixed. I moved the code adjustments I did into one of the last functions that passes the stuff. It's working for me now! Code (markup):
Almost almost there code tag is perfect now! congratulations But I notice some issues in other tags: Look how is showing... Post content: http://i36.tinypic.com/28wjy49.jpg Post view: http://i33.tinypic.com/es564z.jpg
Omg I'm starting to remember my headaches with phpBB2 vividly now.. haha. I'll try get it sorted out over the next hour, sorry about that!
hehe no problem mate! The only person who needs to say sorry its me, for the hard work that I giving you lol
Wow! If this isn't right, I should just quit developing in PHP.. haha. It works with quote, list, img, url, quote w/ urls, and of course, code. And those are all FOR SURE ones so this should be the last try..should..lol.
mate... PERFECT! You are an GENIOUS Thank you so much mate! THANK YOU! I dont know how to thank you... If you have paypal or epassporte, please pm me with your account. Tomorrow I will give you some money... you deserve!
One last thing... When I click in a url inside of code tags, he opens in the same window... is possible to open in a new window like the urls outside of code tags?