Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2011, 12:28 AM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default htmlentities-ish behavior when posting from a script

Hi-

I am trying to add a post from a custom script. In these posts I want to allow links to images on other websites and to have the HTML code contained in the post honored without setting the "Allow HTML" option for the forum in question to "Yes". IOW, when you post via the vB quick reply or advanced webpage, it allows you to enter links to other websites for pictures, etc. Then when you View -> Source of that result from your browser, you see this:

HTML Code:
the trend is sure<br />
      catching up, my cousin shot a picture of this in my town recently <br /><br />
      <p><img src="http://somewebsite/blah/blah/blah.jpg" /> </p><br />
      <a href="http://somewebsite.com/" rel="nofollow" class="external">http://somewebsite.com/</a>
However when I add the same post via my script I get this:

HTML Code:
&lt;br /&gt;the trend is sure<br />
      catching up, my cousin shot a picture of this in my town recently &lt;br /&gt;<br />
      &lt;p&gt;&lt;img src=&quot;http://somewebsite/blah/blah/blah.jpg&quot; /&gt; &lt;/p&gt;<br />
      &lt;a href=&quot;http://somewebsite.com/&quot; rel=&quot;nofollow&quot; class=&quot;external&quot;&gt;http://somewebsite.com/&lt;/a&gt;
And of course the former is rendered just like you'd expect and want, while the latter shows up as just a bunch of HTML code in your post, thus:

Code:
<br />the trend is sure
catching up, my cousin shot a picture of this in my town recently <br />
<p><img src="http://somewebsite/blah/blah/blah.jpg" /> </p>
<a href="http://somewebsite.com/" rel="nofollow" class="external">http://somewebsite.com/</a>
So it's almost as though the pagetext from the post is run through htmlentities or some equivalent prior to being entered in the DB. I did a search through the code base and only found one htmlentities call and it didn't seem appropriate, so I kept looking at other options. I went through the newreply.php source and did a search on this forum but didn't find anything. I finally decided to give up the ghost and ask, as I am trying to wrap this work up.

So ... anyone know how to prevent this behavior when creating a post from a script without enabling "Allow HTML" via the admincp? I know it can be done because I have that option turned off right now and I get the results shown above.

Thanks!
Reply With Quote
  #2  
Old 05-08-2011, 12:56 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How is your script adding a post? You're saying that the text you're posting doesn't have the entities in it, then you do something to make it a post and it comes out with the entities?
Reply With Quote
  #3  
Old 05-08-2011, 01:03 AM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi kh99-

Thanks for replying. This is what I have for adding a post to an existing thread, but I get the same result regardless of whether or not I use the vB_DataManager_Post or the vB_DataManager_Thread_FirstPost object.

PHP Code:
function AddNewPostToExistingThread$postData )
{
   global 
$vbulletin;

   
/*
    * Create the DM object
    */
   
$newPost = new vB_DataManager_Post$vbulletinERRTYPE_ARRAY );

   
/*
    * Populate the DM object
    */
   
$foruminfo fetch_foruminfo(    $postData'forumid'   ] );
   
$threadinfo fetch_threadinfo(  $postData'threadid'  ] );
   
$newPost->set_info'forum',     $foruminfo               );
   
$newPost->set_info'thread',    $threadinfo              );
   
$newPost->set'threadid',       $postData'threadid'  ] );
   
$newPost->set'title',          $postData'subject'   ] );
   
$newPost->set'userid',         $postData'userid'    ] );
   
$newPost->set'pagetext',       $postData'body'      ] );
   
$newPost->set'dateline',       $postData'dateline'  ] );
   
$newPost->set'allowsmilie',    1                        );
   
$newPost->set'visible',        1                        );

   
/*
    * Pre-save the DM object
    */
   
$newPost->pre_save();

   
# Check for and process errors
   
if( count$newPost->errors ) )
      
// do something to report errors back to log
      
print "Could not add post {$postData'title' ]}. Error List:\n";
      foreach( 
$newPost->errors as $error )
      {
         print 
"   -> $error\n";
      }
      unset( 
$newPost );
      return 
false;

   }
   else
   {
      
// Do the full save
      
$newPostID $newPost->save();
      
// do something to report threadid back to log
      // if you want that level of reporting
      
print "Added post {$postData'title' ]}. Post ID = $newPostID\n";
      
build_thread_counters$newPostID             );
      
build_forum_counters(  $postData'forumid' ] );
      unset( 
$newPost );
      return 
true;

   } 
// if-else errors

// AddNewPostToExistingThread() 
As for your second question, the results between entering the identical text via the quick reply or advanced editor while logged into the forum versus from a script produce different results. Also, strangely enough I seem to recall creating a post via a script where this worked (HTML not displayed as HTML text but rather used to render the display), but that was late last night and so I don't recall now how that occurred. And unfortunately I cannot reproduce it. [grumble]

EDIT: I forgot to mention that I tried running the script both with the "Allow HTML" option set to "Yes" and with it set to "No". Either way produces the same result. The thought I originally had (which was a guess as I'm still new to vB) was that if the post was added when the "Allow HTML" option setting was "Yes" then the content would not be converted via htmlentities and stored in the DB just as you'd want it. And with that option set to "No", then you would have your HTML in your content converted and stored in the DB in that manner. To test that theory, I would set "Allow HTML" to "Yes" then run the script. Then change the setting to "No" and run the script again. As I mentioned, I got the same result. So much for that theory...

Thanks!

--------------- Added [DATE]1304821978[/DATE] at [TIME]1304821978[/TIME] ---------------

UPDATE: I found some reference to converting to BB code in newreply.php, so I am going to look into that. Could it be that I simply need to wrap BB tags around the HTML code and that would take care of it? Boy but that would be great if it turns out to be that simple...
Reply With Quote
  #4  
Old 05-08-2011, 01:40 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I was going to say that I don't think you can format a post using HTML if you have "Allow HTML" set to no, it has to be bbcode. If you set allow html to yes, post some html, then set it back to no it will just show the tags instead of formatting it (which means you can't just put HTML in a post in the db). So you'll probably have to convert your post to bbcode somehow. ETA: well, I guess what I should say is that I'm not sure if it can be done. It's possible that there's a field in the db somewhere that says what kind of data is in the pagetext field that would allow it to work.

Also, there's a function called htmlspecialchars_uni() that's the equivalent to htmlentities you mentiond, it's called in a lot of places.

Other than that, I think you thanked me too soon because I thought I had an idea of what might be going on, but now I don't know. I'll keep looking at it...EDIT: great, glad you got it working.
Reply With Quote
  #5  
Old 05-08-2011, 01:57 AM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FINAL ANSWER:

Sure enough that was the key. By simply making a call into the wysiwyg functions and exchanging the HTML tags for BB equivalents, everything works as expected. I realize that this is true only because the forum in which this post is being made allows BB code. If that option was switched off, then naturally it wouldn't render the page as expected. However vB discourages use of HTML tags - and for good reason - not BB codes, so I'll adhere to that recomendation.

BTW, here was the line of code that made the difference. This was located outside my function shown above, in a data prepare step. No other changes made to my function:

PHP Code:
$mypost['body'] = convert_wysiwyg_html_to_bbcode($mypost['body']); 
And of course you'll need the include somewhere within the scope of the above call:

PHP Code:
require_once( LMDIR '/includes/functions_wysiwyg.php'); 
Thanks! Hope this helps someone in the future.
Reply With Quote
Reply


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 07:28 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.03649 seconds
  • Memory Usage 2,237KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_code
  • (2)bbcode_html
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete