ILIAS  release_4-4 Revision
HTMLPurifier_AttrDef_CSS_Font Class Reference

Validates shorthand CSS property font. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_Font:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_Font:

Public Member Functions

 __construct ($config)
 
 validate ($string, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition. More...
 
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA. More...
 
 make ($string)
 Factory method for creating this class from a string. More...
 

Protected Attributes

 $info = array()
 Local copy of component validators. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized. More...
 
 $required = false
 Tells us whether or not an HTML attribute is required. More...
 
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
 
 expandCSSEscape ($string)
 Parses a possibly escaped CSS string and returns the "pure" version of it. More...
 

Detailed Description

Validates shorthand CSS property font.

Definition at line 6 of file Font.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_Font::__construct (   $config)

Definition at line 19 of file Font.php.

19  {
20  $def = $config->getCSSDefinition();
21  $this->info['font-style'] = $def->info['font-style'];
22  $this->info['font-variant'] = $def->info['font-variant'];
23  $this->info['font-weight'] = $def->info['font-weight'];
24  $this->info['font-size'] = $def->info['font-size'];
25  $this->info['line-height'] = $def->info['line-height'];
26  $this->info['font-family'] = $def->info['font-family'];
27  }

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_Font::validate (   $string,
  $config,
  $context 
)

Definition at line 29 of file Font.php.

References $r, $size, and HTMLPurifier_AttrDef\parseCDATA().

29  {
30 
31  static $system_fonts = array(
32  'caption' => true,
33  'icon' => true,
34  'menu' => true,
35  'message-box' => true,
36  'small-caption' => true,
37  'status-bar' => true
38  );
39 
40  // regular pre-processing
41  $string = $this->parseCDATA($string);
42  if ($string === '') return false;
43 
44  // check if it's one of the keywords
45  $lowercase_string = strtolower($string);
46  if (isset($system_fonts[$lowercase_string])) {
47  return $lowercase_string;
48  }
49 
50  $bits = explode(' ', $string); // bits to process
51  $stage = 0; // this indicates what we're looking for
52  $caught = array(); // which stage 0 properties have we caught?
53  $stage_1 = array('font-style', 'font-variant', 'font-weight');
54  $final = ''; // output
55 
56  for ($i = 0, $size = count($bits); $i < $size; $i++) {
57  if ($bits[$i] === '') continue;
58  switch ($stage) {
59 
60  // attempting to catch font-style, font-variant or font-weight
61  case 0:
62  foreach ($stage_1 as $validator_name) {
63  if (isset($caught[$validator_name])) continue;
64  $r = $this->info[$validator_name]->validate(
65  $bits[$i], $config, $context);
66  if ($r !== false) {
67  $final .= $r . ' ';
68  $caught[$validator_name] = true;
69  break;
70  }
71  }
72  // all three caught, continue on
73  if (count($caught) >= 3) $stage = 1;
74  if ($r !== false) break;
75 
76  // attempting to catch font-size and perhaps line-height
77  case 1:
78  $found_slash = false;
79  if (strpos($bits[$i], '/') !== false) {
80  list($font_size, $line_height) =
81  explode('/', $bits[$i]);
82  if ($line_height === '') {
83  // ooh, there's a space after the slash!
84  $line_height = false;
85  $found_slash = true;
86  }
87  } else {
88  $font_size = $bits[$i];
89  $line_height = false;
90  }
91  $r = $this->info['font-size']->validate(
92  $font_size, $config, $context);
93  if ($r !== false) {
94  $final .= $r;
95  // attempt to catch line-height
96  if ($line_height === false) {
97  // we need to scroll forward
98  for ($j = $i + 1; $j < $size; $j++) {
99  if ($bits[$j] === '') continue;
100  if ($bits[$j] === '/') {
101  if ($found_slash) {
102  return false;
103  } else {
104  $found_slash = true;
105  continue;
106  }
107  }
108  $line_height = $bits[$j];
109  break;
110  }
111  } else {
112  // slash already found
113  $found_slash = true;
114  $j = $i;
115  }
116  if ($found_slash) {
117  $i = $j;
118  $r = $this->info['line-height']->validate(
119  $line_height, $config, $context);
120  if ($r !== false) {
121  $final .= '/' . $r;
122  }
123  }
124  $final .= ' ';
125  $stage = 2;
126  break;
127  }
128  return false;
129 
130  // attempting to catch font-family
131  case 2:
132  $font_family =
133  implode(' ', array_slice($bits, $i, $size - $i));
134  $r = $this->info['font-family']->validate(
135  $font_family, $config, $context);
136  if ($r !== false) {
137  $final .= $r . ' ';
138  // processing completed successfully
139  return rtrim($final);
140  }
141  return false;
142  }
143  }
144  return false;
145  }
$size
Definition: RandomTest.php:79
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:58
$r
+ Here is the call graph for this function:

Field Documentation

◆ $info

HTMLPurifier_AttrDef_CSS_Font::$info = array()
protected

Local copy of component validators.

Note
If we moved specific CSS property definitions to their own classes instead of having them be assembled at run time by CSSDefinition, this wouldn't be necessary. We'd instantiate our own copies.

Definition at line 17 of file Font.php.


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