phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

handling of [url=]


 
Search this topic... | Search MOD Requests... | Search Box
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Author Message
noisy
Board Member



Joined: 04 Jun 2011

Posts: 35



PostPosted: Mon Jun 06, 2011 7:20 pm 
Post subject: handling of [url=]

Does any one know if there is a way to make the [url=]...[/url] bbcode tags "disappear" from the post if the author does not input the bbcode correctly?

The instance i need to "disappear" is this

[url=]whatever[/url]

This will be parsed as text since the =value is missing. I want to make the whole thing invisible in post body, as long as the =value is missing of course.

Since my [url] bbcode is somewhat modified, i was thinking to use a "clean" bbcode that does the same thing, the [target] bbcode which can be found here http://www.phpbbhacks.com/download/258

From what i understand the bbcode is parsed twice, once when submitted and once when a user browses the topic. I guess what i want is that in this second parse, the specific instance [url=]whatever[/url] or [target=]whatever[/target] to be ignored completely. Not just the tags, but the "whatever" as well.

Do i make sense? possible or not possible?
Back to top
noisy
Board Member



Joined: 04 Jun 2011

Posts: 35



PostPosted: Mon Jun 06, 2011 7:25 pm 
Post subject: Re: handling of [url=]

just in case some one wants to help, the [target] bbcode mod is this

Code:

#
#-----[ ACTION: open ]--------------------------------
#
   includes/bbcode.php
#
#-----[ ACTION: find ]--------------------------------
#

   $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
   $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url4']);

#
#-----[ ACTION: add below ]---------------------------
#

   $bbcode_tpl['target1'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['target']);
   $bbcode_tpl['target1'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['target1']);
   
   $bbcode_tpl['target2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['target']);
   $bbcode_tpl['target2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['target2']);
   
   $bbcode_tpl['target3'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['target']);
   $bbcode_tpl['target3'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['target3']);
   
   $bbcode_tpl['target4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['target']);
   $bbcode_tpl['target4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['target4']);


#
#-----[ ACTION: find ]--------------------------------
#

   // [email]user@domain.tld[/email] code..
   $patterns[5] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
   $replacements[5] = $bbcode_tpl['email'];


#
#-----[ ACTION: add below ]---------------------------
#

   // [target]xxxx://www.phpbb.com[/target] code..
   $patterns[6] = "#\[target\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/target\]#si";
   $replacements[6] = $bbcode_tpl['target1'];

   // [target]www.phpbb.com[/target] code.. (no xxxx:// prefix).
   $patterns[7] = "#\[target\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/target\]#si";
   $replacements[7] = $bbcode_tpl['target2'];

   // [target=xxxx://www.phpbb.com]phpBB[/target] code..
   $patterns[8] = "#\[target=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\[/target\]#si";
   $replacements[8] = $bbcode_tpl['target3'];

   // [target=www.phpbb.com]phpBB[/target] code.. (no xxxx:// prefix).
   $patterns[9] = "#\[target=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\[/target\]#si";
   $replacements[9] = $bbcode_tpl['target4'];

#
#-----[ ACTION: save close upload ]-------------------
#



#
#-----[ ACTION: open ]--------------------------------
#
   templates/xxxx/bbcode.tpl
#
#-----[ ACTION: find ]--------------------------------
#

<!-- BEGIN url -->
<a href="{URL}" target="_blank" class="postlink">{DESCRIPTION}</a>
<!-- END url -->

#
#-----[ ACTION: add below ]---------------------------
#

<!-- BEGIN target -->
<a href="{URL}" target="_self" class="postlink">{DESCRIPTION}</a>
<!-- END target -->


#
#-----[ ACTION: save close upload ]-------------------
#
#
#
######### [ EOF ] #############################################




the only difference between the [target] and the native [url] bbcode is the target="_self" , which doesn't make a difference for me.
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Mon Jun 06, 2011 11:40 pm 
Post subject: Re: handling of [url=]

As far as I can see, you just need to add two replacements to line ~217 in includes/bbcode.php. I suck at regular expressions, so I can't give you the actual code, but basically you'd have to add a replacement for "[url=not a url]not a url[/url]" and one for "[url]not a url[/url]". The tricky part is using regular expressions to represent "not a url" - I couldn't figure that out to save my life.
And instead of $replacements[] = $bbcode_tpl['url2'];, you'd be using $replacements[] = "";. Although I would personally recommend replacing it with something like "Invalid link code" instead so your users understand why their links aren't showing up.
Back to top
noisy
Board Member



Joined: 04 Jun 2011

Posts: 35



PostPosted: Tue Jun 07, 2011 5:24 am 
Post subject: Re: handling of [url=]

Salvatos wrote:
As far as I can see, you just need to add two replacements to line ~217 in includes/bbcode.php. I suck at regular expressions, so I can't give you the actual code, but basically you'd have to add a replacement for "[url=not a url]not a url[/url]" and one for "[url]not a url[/url]". The tricky part is using regular expressions to represent "not a url" - I couldn't figure that out to save my life.
And instead of $replacements[] = $bbcode_tpl['url2'];, you'd be using $replacements[] = "";. Although I would personally recommend replacing it with something like "Invalid link code" instead so your users understand why their links aren't showing up.



i dont want to prevent ANY "not an url" error in the bbcode format. I only want to prevent this specific error [url=]whatever[/url], where the = parameter is empty!

This would make things easier for some one to create this replacement expression, no??
Back to top
noisy
Board Member



Joined: 04 Jun 2011

Posts: 35



PostPosted: Tue Jun 07, 2011 6:29 am 
Post subject: Re: handling of [url=]

i think i did it, but i aint sure if my code is correct... I used the [target] bbcode, which is the same exactly as the native un-moded [url] bbcode

$patterns[10] = "#\[target=()\](.*?)\[/target\]#si";
$replacements[10] = "";

this will replace any instance of this nature [target=]whatever[/target] with blank.

I tested it, it works fine.

If some one with php knowledge could verify this is the correct setup, that would be great icon_smile.gif. Thanks in advance


EDIT: This is solved now. Correct expresion is

$patterns[10] = "#\[target=\].*?\[/target\]#si";
$replacements[10] = "";
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0291 seconds using 16 queries. (SQL 0.0027 Parse 0.0008 Other 0.0256)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo