XF 2.3 Creating a thread/post with RAW HTML/JS, etc. as the message

frm

Well-known member
Is there a function that you can push a message containing RAW HTML, etc., through that would convert it to BBCode (stripping it of everything that can't be posted, such as Javascript, etc.), or would I need to strip it down to basic HTML then regex the HTML, etc., to wrap it in BBCode before saving the thread?

Or is this enough:
PHP:
$post->message = "<b>RAW text including</b> code that should be converted to BBCode and code typically not allowed <div></div> etc. stripped";

For results:
RAW text including code that should be converted to BBCode and code typically not allowed etc. stripped
[B]RAW text including[/B]

Thanks
 
I don't think there is something that goes other way around from html to bbcode.
It would quite complicated considering potential custom bbcodes.
 
The editor represents messages as HTML so by necessity we must be able to convert in either direction:

PHP:
$bbCode = \XF\Html\Renderer\BbCode::renderFromHtml($html);
 
The editor represents messages as HTML so by necessity we must be able to convert in either direction:
Would that strip <div> <span>s and whatnot that are accidentally copied over (copy/paste-plain-text) or try its best to render what it can as BBCode (even broken images)?
 
It will render a string of HTML into a string of BBCode, stripping tags which cannot be represented. It will not strip tags which are escaped in the input (ie. &lt;div&gt;) if that's what you mean. It has no notion of whether an image is broken or not.
 
It will render a string of HTML into a string of BBCode, stripping tags which cannot be represented. It will not strip tags which are escaped in the input (ie. &lt;div&gt;) if that's what you mean. It has no notion of whether an image is broken or not.
Would it convert &amp; to & or do I need to keep that in my code? Sometimes copy-paste plain text includes that and I have it replaced with & before I run it through as a message. Other than that, I don't think &lt; &gt; will be problematic.
 
As in unescape it? No, it will be left as-is.
So looks like I'll need to examine some imported messages and see which ones need to be converted, to do the conversion on my own prior to reentering it as a message, as I've been doing, since the importers for Invision didn't do it (looks like by design).

Thanks!
 
I misunderstood your previous message, &amp; in the input will be converted into & in the output. In fact, even &gt; and &lt; should be unescaped in the output, but not parsed as HTML.
 
I misunderstood your previous message, &amp; in the input will be converted into & in the output. In fact, even &gt; and &lt; should be unescaped in the output, but not parsed as HTML.
Ok, so if I'm understanding you, I can pass &amp; &gt; &lt; in a message and save it with that, but the thread view of the message saved will show & > < respectively? Because that's the issue I had with the Invision importers... they are either &amp; in the database when they should've been converted to &, but I'm unsure of the Invision DB if they were &amp; or not (need to look) to see if there's a bug with the importers by not escaping them and making it human-readable in a thread/post.

So, trying to convert it this way as opposed to database manipulation, for the purpose of learning how to develop with XF, as there's no real goal or objective that I have to try and do something else that I can't just outsource for immediate deployment.
 
I could send you xf_post and the corresponding Invision table to take a look to see if there's a bug in how they were imported to give me &amp; &gt; &lt; instead of human-readable & > < in the newly created messages if you'd like.

But I'm not really concerned about that since I already did the 2 hour+ long import and don't want to go through that (again). However, it might give you an idea whether the importers need to be updated. I think I reported it as a bug...

(Nope, just direct URLs of images that should have been converted to XF storage not wrapping in [IMG] with the newly created path)
https://xenforo.com/community/threa...invision-to-new-location-bbcode-on-xf.228049/

But, the &amp; &gt; &lt; is something that I recently noticed in some messages that need fixed, though I don't know if this is by design or if Invision had them as & and XF made them &amp; or vice-versa to make a report there.
 
Ok, so if I'm understanding you, I can pass &amp; &gt; &lt; in a message and save it with that, but the thread view of the message saved will show & > < respectively?
If you pass &amp; &gt; &lt in, you'll get & > < out. Posts are stored in the database as BB code, so the latter is what should be there. When rendering BBCode to back into HTML for presentation, the inverse happens.

Messages should display roughly the same as they did in IPS, regardless of the underlying markup language. If it doesn't, file a bug report.
 
  • Like
Reactions: frm
Back
Top Bottom