HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Manipulating post output?

I was trying to manipulate the contents of a post before it is displayed to the user. Basically what I am trying to do is similar to emoticon processing of old before unicode-emotes, i.e take a certain code phrase and replace it with a text string plus an image and some html formatting codes and display it inline in the sentence.

Now, I've found that by handling discussionController_render_before I can access the Body property of the discussion and manipulate that easy enough. Problem is that this data is written using the Rich editor, and there seems to be serious limitations to how I can insert an image into that data.

So, what I am looking for is either one of these things:

  • Is there a way to include a HTML snippet into the rich editor data and have it render it as actual html for the browser to process (so far, my attempts have resulted in it escaping the characters and just have the html code printed out in the post). Are this possible? Any special escaping that needs to be done?
  • Is there a way with the rich text format to specify that an image should be inline in the text?
  • Is there a way to access the rendered data from the post after it has been rendered to html format, but before it is embedded in the page and sent to the user? I found a FormatBody property in the discussion object which seems to be the rendered text, but changing it doesn't seem to do anything, but maybe I am doing something wrong or handling the wrong event.


This is the sample code I've been using when working with this, doesn't do anything fancy right now other than trying to introduce span tags around the codeword (any word prefixed and suffixed by : in this test), which just results in these span tags showing up in the post as text.

public function discussionController_render_before($sender,$args){

       $discussion = val('Discussion', $sender);

       if(isset($discussion->Body) && $discussion->Format == "Rich"){
               $discussion->Body = preg_replace('/:([a-zA-Z0-9]*?):/','<span style=\\"font-weight:900\\">$1</span>',$discussion->Body);
       }

}

Any pointers would be much appreciated.

Note that I am just trying to manipulate the post when displayed in the forum, I haven't really that much need displaying it correctly in the post editor window to mess with the editor itself. (And yes, I know I am only handling the discussion right now and not the comments)

Comments

Sign In or Register to comment.