Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 14 Jul 2012, 18:33
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
vBulletin Custom Plugin Options - Changing Carriage Returns!

Hey again all,
I've been developing a plugin, and in the vBulletin Options for this plugin, there's a textarea where users can input a paragraph for their rules.

I have this following contents in my database, which is being called:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

^That is EXACTLY as it is in the database, which causes my plugin not to work.
An image (just to be more clear):


Now, in the database, there is no \r or \n or anything of the sort. It is exactly as I mentioned above.

I'm working primarily with JavaScript (innerHTML), and need to find a way to make carriage returns be interpreted as <br /> tags and NOT as physical carriage returns.

Thanks in advance for any help,
Mark

P.S. If someone needs the .js file, let me know

Last edited by Mko : 14 Jul 2012 at 18:50.
Reply With Quote
  #2  
Old 14 Jul 2012, 18:43
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Real name: Simon
you'd want to use \n for new line or (and it might be deprocated) \r for return, however \n works for me

--------------- Added 14 Jul 2012 at 18:43 ---------------

Just did a quick Google and found this http://www.w3schools.com/js/js_special_characters.asp
Reply With Quote
  #3  
Old 14 Jul 2012, 18:47
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by Simon Lloyd View Post
you'd want to use \n for new line or (and it might be deprocated) \r for return, however \n works for me

--------------- Added 14 Jul 2012 at 14:43 ---------------

Just did a quick Google and found this http://www.w3schools.com/js/js_special_characters.asp
I might've not been clear. My apologies.

Basically, I have this following contents in my database, which is being called:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

^That is EXACTLY as it is in the database.
An image (just to be more clear):


Now, in the database, there is no \r or \n or anything of the sort. It is exactly as I mentioned above.

My question remains: is there any way to make carriage returns be interpreted as <br /> tags?
Reply With Quote
  #4  
Old 14 Jul 2012, 19:53
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Real name: Simon
You might try you using str replace and replace \n (i know what you said but give it a try! or \r), like this:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

--------------- Added 14 Jul 2012 at 19:54 ---------------

The picture of your database shows that each character is in a seperate row?
Reply With Quote
  #5  
Old 14 Jul 2012, 20:39
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by Simon Lloyd View Post
You might try you using str replace and replace \n (i know what you said but give it a try! or \r), like this:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

--------------- Added 14 Jul 2012 at 15:54 ---------------

The picture of your database shows that each character is in a seperate row?
Didn't work, sadly. Thanks though!

&no, it's just a cell in the db program I'm using.
Reply With Quote
  #6  
Old 14 Jul 2012, 21:00
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Real name: Simon
in that case do you can split string like this in js
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #7  
Old 14 Jul 2012, 21:02
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by Simon Lloyd View Post
in that case do you can split string like this in js
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
Still no success.

I had an idea though. Regarding vB Templates, when they're saved, they don't print each carriage return. So, does anyone know how they do it?
Reply With Quote
  #8  
Old 14 Jul 2012, 21:30
kh99's Avatar
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Try this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Where $option is the string from the database, and $string is what you'll use in your template for the js variable, in single quotes, like:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


This assumes that what's being entered and saved in the db is not html. If it is, you don't want the htmlspecialchars() in there (and then they really should be entering the <br> tags themselves, but that's OK).

Edit: Another thought - you could allow bbcode markup, and then when you pass it through the bbcode compiler it will change \n to <br>.


Originally Posted by Mko View Post
Regarding vB Templates, when they're saved, they don't print each carriage return. So, does anyone know how they do it?
The templates are html, so you'd have to explicitly use <br> where you wanted them in the output.
__________________
Please don't PM me - post your questions in the appropriate forum.
Please don't PM me to ask me to read your thread.

Last edited by kh99 : 14 Jul 2012 at 21:36.
Reply With Quote
  #9  
Old 14 Jul 2012, 22:24
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by kh99 View Post
Try this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Where $option is the string from the database, and $string is what you'll use in your template for the js variable, in single quotes, like:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This assumes that what's being entered and saved in the db is not html. If it is, you don't want the htmlspecialchars() in there (and then they really should be entering the <br> tags themselves, but that's OK).

Edit: Another thought - you could allow bbcode markup, and then when you pass it through the bbcode compiler it will change \n to <br>.




The templates are html, so you'd have to explicitly use <br> where you wanted them in the output.
So close, but yet it doesn't work. :/
Basically, if I've still been unclear, I'm calling the variable (which I declare in a template):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Into my .js file:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So, my problem is basically how do I manipulate the input in the ACP in JavaScript and not in PHP?

Last edited by Mko : 14 Jul 2012 at 22:42.
Reply With Quote
  #10  
Old 15 Jul 2012, 02:00
kh99's Avatar
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Hmm...well I was thinking you might be able to fix the problem on the php side by changing what value you're giving the RULES var, and that would require another plugin instead of just using $vboptions[ishout_rules] directly in a template. But maybe I don't understand what the issue is. Is it all working except that InfernoShoutbox.userframe doesn't show the right value, or does it not work at all because the "var RULES = " line isn't valid js?
__________________
Please don't PM me - post your questions in the appropriate forum.
Please don't PM me to ask me to read your thread.
Reply With Quote
  #11  
Old 15 Jul 2012, 10:20
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by kh99 View Post
Hmm...well I was thinking you might be able to fix the problem on the php side by changing what value you're giving the RULES var, and that would require another plugin instead of just using $vboptions[ishout_rules] directly in a template. But maybe I don't understand what the issue is. Is it all working except that InfernoShoutbox.userframe doesn't show the right value, or does it not work at all because the "var RULES = " line isn't valid js?
Forgive me, I might've been unclear, haha

Basically, here's what I've got (my whole .js code):
http://paste2.org/p/2073301#line-549
As you can see, I'm already modifying the variable RULES on line 549 to change all \n tags to be <br />.

Now, the RULES var is called from an option in a setting on my Forum. In this setting, as you can probably guess, you can input a description of your rules that will display.

I have the following defined in a template:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Before I go on, someone on another forum told me:
A JavaScript error is probably occurring. Based on the limited information that I have, I would guess that this is due to the way you're loading the rules value into JavaScript. You probably have a variable definition that looks like:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
...leading me to understand that I'm bringing in invalid js.

So, the contents of the ishout_rules option that are like:

...would in fact not be valid js and cause an error.


So, if I were to design a Plugin, what hook location should I use and what should it contain? Also, how would I get a custom variable to be accessible by a template?
Or, is there a way to fix the js error?


Thanks,
Mark

Last edited by Mko : 15 Jul 2012 at 10:34.
Reply With Quote
  #12  
Old 15 Jul 2012, 12:00
kh99's Avatar
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
OK, I think this should work: create a plugin using hook parse_templates and code like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Then in your template:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


This won't change the newlines to <br>, but if you are allowing html in your rules then the person writing the rules should put <br> where they want a newlines.

By the way, you asked about how to access a variable in the other thread and I'm sorry it didn't occur to me that you might have problems like this with a string.
__________________
Please don't PM me - post your questions in the appropriate forum.
Please don't PM me to ask me to read your thread.
Reply With Quote
  #13  
Old 15 Jul 2012, 13:37
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Real name: Mark
Originally Posted by kh99 View Post
OK, I think this should work: create a plugin using hook parse_templates and code like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then in your template:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This won't change the newlines to <br>, but if you are allowing html in your rules then the person writing the rules should put <br> where they want a newlines.

By the way, you asked about how to access a variable in the other thread and I'm sorry it didn't occur to me that you might have problems like this with a string.
Figured it out, thanks for your help!
I had to put some PHP code into the cache_templates page then modify the output in my .js file
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 06:23.

Layout Options | Width: Wide Color: