Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I stop HTML Filtering through on Sitewide / recent posts widget?

  • Avatar of georgef101
    georgef101
    Participant

    @georgef101

    All movies and pictures filter through on the Site Wide Activty feed and the Recent Site Wide Posts.

    Sometimes it ok, but when a video embeds into the recent site wide posts which is almost triple the size of the widget, it doesn’t look too good.

    How do I srip the code from filtering through to the widgets?

    Thanks!

    George

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of Anton
    Anton
    Participant

    @antonrsaopencirclecoza

    anyone?

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    I’ve worked on a similar problem last weekend and found this extremely usefull function:

    function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){
    $string = strip_tags($string,$allowtags);
    if (!is_null($allowattributes)) {
    if(!is_array($allowattributes))
    $allowattributes = explode(",",$allowattributes);
    if(is_array($allowattributes))
    $allowattributes = implode(")(?<!",$allowattributes);
    if (strlen($allowattributes) > 0)
    $allowattributes = "(?<!".$allowattributes.")";
    $string = preg_replace_callback("/<[^>]*>/i",create_function(
    '$matches',
    'return preg_replace("/ [^ =]*'.$allowattributes.'=("[^"]*"|'[^']*')/i", "", $matches[0]);'
    ),$string);
    }
    return $string;
    }

    You can apply it on a piece of content like this:

    strip_tags_attributes($content, '<p><a><img><object><param><embed>','href,src,allowfullscreen,type');

    The tags and attributes in this example are allowed, everything else is stripped. This example also leaves embedded video, but because the width and height attributes are stripped you can define those in the CSS so the object/embed fits in your widget. Or just disallow object/embed.

    Where and how you should apply this function in your case I haven’t figured out yet. Let me know, I should probably use this myself.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.