Dotclear 2.25
Loading...
Searching...
No Matches
htmlFilter Class Reference

HTML code filter. More...

Public Member Functions

 __construct (bool $keep_aria=false, bool $keep_data=false, bool $keep_js=false)
 
 removeHosts (... $args)
 
 removeTags (... $args)
 
 removeAttributes (... $args)
 
 removeArrayAttributes (array $attrs)
 
 removePatternAttributes (... $args)
 
 removeTagAttributes (string $tag,... $args)
 
 setTags (array $tags)
 
 apply (string $str, bool $tidy=true)
 

Data Fields

 $content
 

Detailed Description

HTML code filter.

This class removes all unwanted tags and attributes from an HTML string.

This was inspired by Ulf Harnhammar's Kses (http://sourceforge.net/projects/kses)

Constructor & Destructor Documentation

◆ __construct()

__construct ( bool  $keep_aria = false,
bool  $keep_data = false,
bool  $keep_js = false 
)

Constructs a new instance.

Parameters
bool$keep_ariaKeep aria attributes
bool$keep_dataKeep data elements
bool$keep_jsKeep javascript elements

References removeArrayAttributes(), removeAttributes(), removeHosts(), removePatternAttributes(), and removeTags().

Member Function Documentation

◆ removeHosts()

removeHosts (   $args)

Append hosts

Appends hosts to remove from URI. Each method argument is a host. Example:

<?php $filter = new htmlFilter(); $filter->removeHosts('javascript'); ?>

Parameters
mixed...$args The arguments

Referenced by __construct().

◆ removeTags()

removeTags (   $args)

Append tags

Appends tags to remove. Each method argument is a tag. Example:

<?php $filter = new htmlFilter(); $filter->removeTags('frame','script'); ?>

Parameters
mixed...$args The arguments

Referenced by __construct().

◆ removeAttributes()

removeAttributes (   $args)

Append attributes

Appends attributes to remove. Each method argument is an attribute. Example:

<?php $filter = new htmlFilter(); $filter->removeAttributes('onclick','onunload'); ?>

Parameters
mixed...$args The arguments

Referenced by __construct().

◆ removeArrayAttributes()

removeArrayAttributes ( array  $attrs)

Append array of attributes

Appends attributes to remove. Example:

<?php $filter = new htmlFilter(); $filter->removeAttributes(['onload','onerror']); ?>

Parameters
array$attrsThe attributes

Referenced by __construct().

◆ removePatternAttributes()

removePatternAttributes (   $args)

Append attribute patterns

Appends attribute patterns to remove. Each method argument is an attribute pattern. Example:

<?php $filter = new htmlFilter(); $filter->removeAttributes('data-.*'); ?>

Parameters
mixed...$args The arguments

Referenced by __construct().

◆ removeTagAttributes()

removeTagAttributes ( string  $tag,
  $args 
)

Append attributes for tags

Appends attributes to remove from specific tags. Each method argument is an array of tags with attributes. Example:

<?php $filter = new htmlFilter(); $filter->removeTagAttributes(['a' => ['src','title']]); ?>

Parameters
string$tagThe tag
mixed...$args The arguments

◆ setTags()

setTags ( array  $tags)

Known tags

Creates a list of known tags.

Parameters
array$tagsTags array

◆ apply()

apply ( string  $str,
bool  $tidy = true 
)

Apply filter

This method applies filter on given $str string. It will first try to use tidy extension if exists and then apply the filter.

Parameters
string$strString to filter
boolean$tidyUse tidy extension if present
Returns
string Filtered string

References $config, $content, and html\decodeEntities().

Field Documentation

◆ $content

$content

Referenced by apply().


The documentation for this class was generated from the following file: