1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
19: {
20:
21: public $transform_to = 'span';
22:
23: protected $_size_lookup = array(
24: '0' => 'xx-small',
25: '1' => 'xx-small',
26: '2' => 'small',
27: '3' => 'medium',
28: '4' => 'large',
29: '5' => 'x-large',
30: '6' => 'xx-large',
31: '7' => '300%',
32: '-1' => 'smaller',
33: '-2' => '60%',
34: '+1' => 'larger',
35: '+2' => '150%',
36: '+3' => '200%',
37: '+4' => '300%'
38: );
39:
40: public function transform($tag, $config, $context) {
41:
42: if ($tag instanceof HTMLPurifier_Token_End) {
43: $new_tag = clone $tag;
44: $new_tag->name = $this->transform_to;
45: return $new_tag;
46: }
47:
48: $attr = $tag->attr;
49: $prepend_style = '';
50:
51:
52: if (isset($attr['color'])) {
53: $prepend_style .= 'color:' . $attr['color'] . ';';
54: unset($attr['color']);
55: }
56:
57:
58: if (isset($attr['face'])) {
59: $prepend_style .= 'font-family:' . $attr['face'] . ';';
60: unset($attr['face']);
61: }
62:
63:
64: if (isset($attr['size'])) {
65:
66: if ($attr['size'] !== '') {
67: if ($attr['size']{0} == '+' || $attr['size']{0} == '-') {
68: $size = (int) $attr['size'];
69: if ($size < -2) $attr['size'] = '-2';
70: if ($size > 4) $attr['size'] = '+4';
71: } else {
72: $size = (int) $attr['size'];
73: if ($size > 7) $attr['size'] = '7';
74: }
75: }
76: if (isset($this->_size_lookup[$attr['size']])) {
77: $prepend_style .= 'font-size:' .
78: $this->_size_lookup[$attr['size']] . ';';
79: }
80: unset($attr['size']);
81: }
82:
83: if ($prepend_style) {
84: $attr['style'] = isset($attr['style']) ?
85: $prepend_style . $attr['style'] :
86: $prepend_style;
87: }
88:
89: $new_tag = clone $tag;
90: $new_tag->name = $this->transform_to;
91: $new_tag->attr = $attr;
92:
93: return $new_tag;
94:
95: }
96: }
97:
98:
99: