Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Hoa_Filter_Tag Class Reference
Inheritance diagram for Hoa_Filter_Tag:

Public Member Functions

 getKeepTag ()
 
 getKeepAttribute ()
 
 getKeepValue ()
 
 filter ($string=null)
 
- Public Member Functions inherited from Hoa_Filter_Abstract
 __construct (Array $args=array())
 
 getFilterArgument ($name)
 
 getFilterArguments ()
 
 filter ($string=null)
 

Protected Member Functions

 stripTag ($string= '')
 
- Protected Member Functions inherited from Hoa_Filter_Abstract
 _checkArguments ()
 
 getArguments ()
 

Protected Attributes

 $arguments
 
- Protected Attributes inherited from Hoa_Filter_Abstract
 $arguments = array()
 

Private Member Functions

 setKeepTag ($tag=array())
 
 setKeepAttribute ($attribute=array())
 
 setKeepValue ($value=array())
 

Private Attributes

 $keepTag = array()
 
 $keepAttribute = array()
 
 $keepValue = array()
 

Detailed Description

Definition at line 62 of file Tag.php.

Member Function Documentation

Hoa_Filter_Tag::filter (   $string = null)

Apply a tag filter.

public

Parameters
string$stringThe string to filter.
Returns
string

Definition at line 263 of file Tag.php.

263  {
264 
265  $this->setKeepTag($this->getFilterArgument('tag'));
266  $this->setKeepAttribute($this->getFilterArgument('attribute'));
267  $this->setKeepValue($this->getFilterArgument('value'));
268 
269  return $this->stripTag($string);
270  }
getFilterArgument($name)
Definition: Abstract.php:146
setKeepAttribute($attribute=array())
Definition: Tag.php:123
setKeepValue($value=array())
Definition: Tag.php:141
setKeepTag($tag=array())
Definition: Tag.php:105
stripTag($string= '')
Definition: Tag.php:192

Here is the call graph for this function:

Hoa_Filter_Tag::getKeepAttribute ( )

Get attribute to keep.

public

Returns
array

Definition at line 169 of file Tag.php.

169  {
170 
171  return $this->keepAttribute;
172  }
$keepAttribute
Definition: Tag.php:76

Here is the caller graph for this function:

Hoa_Filter_Tag::getKeepTag ( )

Get tag to keep.

public

Returns
array

Definition at line 158 of file Tag.php.

158  {
159 
160  return $this->keepTag;
161  }

Here is the caller graph for this function:

Hoa_Filter_Tag::getKeepValue ( )

Get attribute value to keep.

public

Returns
array

Definition at line 180 of file Tag.php.

180  {
181 
182  return $this->keepValue;
183  }

Here is the caller graph for this function:

Hoa_Filter_Tag::setKeepAttribute (   $attribute = array())
private

Set a list of attribute to keep.

private

Parameters
array$attributeAttribute to keep.
Returns
array

Definition at line 123 of file Tag.php.

123  {
124 
125  if(!is_array($attribute))
126  $attribute = array($attribute);
127 
128  $old = $this->keepAttribute;
129  $this->keepAttribute = array_map('strtolower', $attribute);
130 
131  return $old;
132  }
$keepAttribute
Definition: Tag.php:76

Here is the caller graph for this function:

Hoa_Filter_Tag::setKeepTag (   $tag = array())
private

Set a list of tag to keep.

private

Parameters
array$tagTag to keep.
Returns
array

Definition at line 105 of file Tag.php.

105  {
106 
107  if(!is_array($tag))
108  $tag = array($tag);
109 
110  $old = $this->keepTag;
111  $this->keepTag = array_map('strtolower', $tag);
112 
113  return $old;
114  }

Here is the caller graph for this function:

Hoa_Filter_Tag::setKeepValue (   $value = array())
private

Set a list of attribute value to keep.

private

Parameters
array$valueValue of attribute to keep.
Returns
array

Definition at line 141 of file Tag.php.

141  {
142 
143  if(!is_array($value))
144  $value = array($value);
145 
146  $old = $this->keepValue;
147  $this->keepValue = array_map('strtolower', $value);
148 
149  return $old;
150  }

Here is the caller graph for this function:

Hoa_Filter_Tag::stripTag (   $string = '')
protected

Initialize parameters.

protected

Parameters
stringstring String to filter.
Returns
void

Definition at line 192 of file Tag.php.

192  {
193 
194  // 0. captured string ;
195  // 1. previous tag string ;
196  // 2. tag ;
197  // 3. attributes and values ;
198  // 4. tag content ;
199  // 5. next tag string.
200  // 1 2 3 4 5
201  $pattern = '#([^>]+)?<([\w]+)(\s?[^>]*)(?(?<!(?:[/\s?]))>(.*?)(?:</\2>)+|>?)([^<]+)?#Ss';
202  $out = '';
203 
204  if(preg_match_all($pattern, $string, $substring, PREG_SET_ORDER)) {
205 
206  foreach($substring as $tags => $tag) {
207 
208  // filter tags
209  $keepA = in_array(strtolower($tag[2]), $this->getKeepTag());
210 
211  // recursive tags filter
212  if(isset($tag[4]) && preg_match($pattern, $tag[4]))
213  $tag[4] = $this->stripTag($tag[4]);
214  $tag[5] = isset($tag[5]) ? $tag[5] : '';
215 
216  // filter attributes and values
217  // pairs keys match with attributes
218  // unpairs keys match with values
219  $attrval = preg_split('#\s*([^=]*)="([^"]*)"\s*/?\s*#Ss',
220  $tag[3], -1,
221  PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
222 
223  $keepB = true;
224  $keepC = true;
225 
226  if(!empty($attrval))
227  for($i = 0, $max = count($attrval); $i < $max; $i += 2) {
228 
229  $keepB &= in_array(strtolower($attrval[$i]), $this->getKeepAttribute());
230  $keepC &= in_array(strtolower($attrval[$i+1]), $this->getKeepValue());
231  }
232 
233  $out .= $tag[1];
234 
235  if(true == $keepA) {
236 
237  $out .= '<' . $tag[2];
238 
239  if(true == $keepB || true == $keepC)
240  $out .= $tag[3];
241 
242  $out .= '>' .
243  (isset($tag[4])
244  ? $tag[4]
245  : '') .
246  '</' . $tag[2] . '>';
247  }
248 
249  $out .= $tag[5];
250  }
251  }
252 
253  return $out;
254  }
getKeepTag()
Definition: Tag.php:158
getKeepValue()
Definition: Tag.php:180
getKeepAttribute()
Definition: Tag.php:169
stripTag($string= '')
Definition: Tag.php:192

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa_Filter_Tag::$arguments
protected
Initial value:
= array(
'tag' => 'specify a list of tag to keep.',
'attribute' => 'specify a list of attribute to keep.',
'value' => 'specify a list of attribute value to keep.'
)

Definition at line 90 of file Tag.php.

Hoa_Filter_Tag::$keepAttribute = array()
private

Definition at line 76 of file Tag.php.

Hoa_Filter_Tag::$keepTag = array()
private

Definition at line 69 of file Tag.php.

Hoa_Filter_Tag::$keepValue = array()
private

Definition at line 83 of file Tag.php.


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