![]() |
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: Code:
a An image (just to be more clear): https://vborg.vbsupport.ru/external/2012/07/37.png 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 :) |
you'd want to use \n for new line or (and it might be deprocated) \r for return, however \n works for me :)
--------------- Added [DATE]1342291426[/DATE] at [TIME]1342291426[/TIME] --------------- Just did a quick Google and found this http://www.w3schools.com/js/js_special_characters.asp |
Quote:
Basically, I have this following contents in my database, which is being called: Code:
a An image (just to be more clear): https://vborg.vbsupport.ru/external/2012/07/37.png 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? |
You might try you using str replace and replace \n (i know what you said but give it a try! or \r), like this:
PHP Code:
The picture of your database shows that each character is in a seperate row? |
Quote:
&no, it's just a cell in the db program I'm using. |
in that case do you can split string like this in js
PHP Code:
|
Quote:
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? :p |
Try this:
PHP 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: Code:
var jsvar = '$jsstring'; 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>. Quote:
|
Quote:
Basically, if I've still been unclear, I'm calling the variable (which I declare in a template): Code:
<script type="text/javascript"> Code:
InfernoShoutbox.userframe.innerHTML = RULES; |
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?
|
Quote:
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: Code:
var RULES = "$vboptions[ishout_rules]"; Quote:
So, the contents of the ishout_rules option that are like: https://vborg.vbsupport.ru/external/2012/07/36.png ...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 |
OK, I think this should work: create a plugin using hook parse_templates and code like this:
Code:
$ishout_rules = addcslashes($vbulletin->options['ishout_rules'], "\r\n'\\"); Then in your template: Code:
var RULES = "$ishout_rules"; 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. |
Quote:
I had to put some PHP code into the cache_templates page then modify the output in my .js file :) |
All times are GMT. The time now is 08:04 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|