Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2012, 05:33 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
b
^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
Reply With Quote
  #2  
Old 07-14-2012, 05:43 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 07-14-2012, 05:47 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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:
Code:
a
b
^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 07-14-2012, 06:53 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
var text "this
is 
some
text "

var 
new_text text.replace("<br />""\n"); 
document.write(new_text); 
--------------- Added [DATE]1342295651[/DATE] at [TIME]1342295651[/TIME] ---------------

The picture of your database shows that each character is in a seperate row?
Reply With Quote
  #5  
Old 07-14-2012, 07:39 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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:
PHP Code:
var text "this
is 
some
text "

var 
new_text text.replace("<br />""\n"); 
document.write(new_text); 
--------------- 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 07-14-2012, 08:00 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

in that case do you can split string like this in js
PHP Code:
text=text.split(' ').join('<br />'
Reply With Quote
  #7  
Old 07-14-2012, 08:02 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Simon Lloyd View Post
in that case do you can split string like this in js
PHP Code:
text=text.split(' ').join('<br />'
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 07-14-2012, 08:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:
PHP Code:
$jsstring addcslashes(nl2br(htmlspecialchars($option)), "'\\"); 

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:
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.
Reply With Quote
  #9  
Old 07-14-2012, 09:24 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Try this:
PHP Code:
$jsstring addcslashes(nl2br(htmlspecialchars($option)), "'\\"); 
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>.




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):
Code:
<script type="text/javascript">
<!--
var RULES = "$vboptions[ishout_rules]";
// -->
</script>
Into my .js file:
Code:
InfernoShoutbox.userframe.innerHTML = RULES;
So, my problem is basically how do I manipulate the input in the ACP in JavaScript and not in PHP?
Reply With Quote
  #10  
Old 07-15-2012, 01:00 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:49 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04193 seconds
  • Memory Usage 2,273KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (6)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete