2006-08-12 20:22:09 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Defines allowed CSS attributes and what their values are.
|
|
|
|
* @see HTMLPurifier_HTMLDefinition
|
|
|
|
*/
|
2007-05-24 21:50:43 +00:00
|
|
|
class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
|
2006-08-12 20:22:09 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
public $type = 'CSS';
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Assoc array of attribute name to definition object.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @type HTMLPurifier_AttrDef[]
|
2006-08-19 23:06:59 +00:00
|
|
|
*/
|
2023-01-12 13:41:13 +00:00
|
|
|
public $info = [];
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Constructs the info array. The meat of this class.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param HTMLPurifier_Config $config
|
2006-08-19 23:06:59 +00:00
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
protected function doSetup($config)
|
|
|
|
{
|
2006-08-12 20:22:09 +00:00
|
|
|
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['left', 'right', 'center', 'justify'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-16 01:39:06 +00:00
|
|
|
$border_style =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['border-bottom-style'] =
|
|
|
|
$this->info['border-right-style'] =
|
|
|
|
$this->info['border-left-style'] =
|
|
|
|
$this->info['border-top-style'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'none',
|
|
|
|
'hidden',
|
|
|
|
'dotted',
|
|
|
|
'dashed',
|
|
|
|
'solid',
|
|
|
|
'double',
|
|
|
|
'groove',
|
|
|
|
'ridge',
|
|
|
|
'inset',
|
|
|
|
'outset'
|
2023-01-12 13:41:13 +00:00
|
|
|
],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['border-style'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_style);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['clear'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['none', 'left', 'right', 'both'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['float'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['none', 'left', 'right'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['normal', 'italic', 'oblique'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['normal', 'small-caps'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['none']),
|
2007-02-14 20:38:51 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_URI()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2007-01-15 01:14:24 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['inside', 'outside'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'disc',
|
|
|
|
'circle',
|
|
|
|
'square',
|
|
|
|
'decimal',
|
|
|
|
'lower-roman',
|
|
|
|
'upper-roman',
|
|
|
|
'lower-alpha',
|
|
|
|
'upper-alpha',
|
|
|
|
'none'
|
2023-01-12 13:41:13 +00:00
|
|
|
],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2007-01-15 01:14:24 +00:00
|
|
|
$this->info['list-style-image'] = $uri_or_none;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['list-style'] = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 16:52:31 +00:00
|
|
|
$this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['capitalize', 'uppercase', 'lowercase', 'none'],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-15 01:14:24 +00:00
|
|
|
$this->info['background-image'] = $uri_or_none;
|
|
|
|
$this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
|
2007-01-15 01:14:24 +00:00
|
|
|
);
|
|
|
|
$this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['scroll', 'fixed']
|
2007-01-15 01:14:24 +00:00
|
|
|
);
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2021-04-22 14:01:00 +00:00
|
|
|
$this->info['background-size'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2021-04-22 14:01:00 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2021-04-22 14:01:00 +00:00
|
|
|
'auto',
|
|
|
|
'cover',
|
|
|
|
'contain',
|
|
|
|
'initial',
|
|
|
|
'inherit',
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2021-04-22 14:01:00 +00:00
|
|
|
),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2021-04-22 14:01:00 +00:00
|
|
|
);
|
|
|
|
|
2008-12-06 07:28:20 +00:00
|
|
|
$border_color =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['border-top-color'] =
|
|
|
|
$this->info['border-bottom-color'] =
|
|
|
|
$this->info['border-left-color'] =
|
|
|
|
$this->info['border-right-color'] =
|
|
|
|
$this->info['background-color'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['transparent']),
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Color()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['background'] = new HTMLPurifier_AttrDef_CSS_Background($config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['border-color'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_color);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
|
|
|
$border_width =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['border-top-width'] =
|
|
|
|
$this->info['border-bottom-width'] =
|
|
|
|
$this->info['border-left-width'] =
|
|
|
|
$this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['thin', 'medium', 'thick']),
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['border-width'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_width);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['letter-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['normal']),
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->info['word-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['normal']),
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->info['font-size'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'xx-small',
|
|
|
|
'x-small',
|
|
|
|
'small',
|
|
|
|
'medium',
|
|
|
|
'large',
|
|
|
|
'x-large',
|
|
|
|
'xx-large',
|
|
|
|
'larger',
|
|
|
|
'smaller'
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->info['line-height'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['normal']),
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true)
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-16 01:39:06 +00:00
|
|
|
$margin =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['margin-top'] =
|
|
|
|
$this->info['margin-bottom'] =
|
|
|
|
$this->info['margin-left'] =
|
|
|
|
$this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto'])
|
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-16 00:18:58 +00:00
|
|
|
// non-negative
|
2006-08-16 01:39:06 +00:00
|
|
|
$padding =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['padding-top'] =
|
|
|
|
$this->info['padding-bottom'] =
|
|
|
|
$this->info['padding-left'] =
|
|
|
|
$this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true)
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['padding'] = new HTMLPurifier_AttrDef_CSS_Multiple($padding);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['text-indent'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto', 'initial', 'inherit'])
|
|
|
|
]
|
2019-07-14 17:20:58 +00:00
|
|
|
);
|
|
|
|
$trusted_min_wh = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2019-07-14 17:20:58 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['initial', 'inherit'])
|
|
|
|
]
|
2019-07-14 17:20:58 +00:00
|
|
|
);
|
|
|
|
$trusted_max_wh = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2019-07-14 17:20:58 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['none', 'initial', 'inherit'])
|
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2009-02-20 00:17:49 +00:00
|
|
|
$max = $config->get('CSS.MaxImgLength');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-29 23:48:54 +00:00
|
|
|
$this->info['width'] =
|
2008-04-22 22:28:54 +00:00
|
|
|
$this->info['height'] =
|
2008-05-23 02:09:43 +00:00
|
|
|
$max === null ?
|
2013-07-16 11:56:14 +00:00
|
|
|
$trusted_wh :
|
|
|
|
new HTMLPurifier_AttrDef_Switch(
|
|
|
|
'img',
|
|
|
|
// For img tags:
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0', $max),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto'])
|
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
),
|
|
|
|
// For everyone else:
|
|
|
|
$trusted_wh
|
|
|
|
);
|
2019-07-14 17:20:58 +00:00
|
|
|
$this->info['min-width'] =
|
|
|
|
$this->info['min-height'] =
|
|
|
|
$max === null ?
|
|
|
|
$trusted_min_wh :
|
|
|
|
new HTMLPurifier_AttrDef_Switch(
|
|
|
|
'img',
|
|
|
|
// For img tags:
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2019-07-14 17:20:58 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0', $max),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['initial', 'inherit'])
|
|
|
|
]
|
2019-07-14 17:20:58 +00:00
|
|
|
),
|
|
|
|
// For everyone else:
|
|
|
|
$trusted_min_wh
|
|
|
|
);
|
|
|
|
$this->info['max-width'] =
|
|
|
|
$this->info['max-height'] =
|
|
|
|
$max === null ?
|
|
|
|
$trusted_max_wh :
|
|
|
|
new HTMLPurifier_AttrDef_Switch(
|
|
|
|
'img',
|
|
|
|
// For img tags:
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2019-07-14 17:20:58 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0', $max),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['none', 'initial', 'inherit'])
|
|
|
|
]
|
2019-07-14 17:20:58 +00:00
|
|
|
),
|
|
|
|
// For everyone else:
|
|
|
|
$trusted_max_wh
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2023-01-12 13:41:13 +00:00
|
|
|
// text-decoration and related shorthands
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2023-01-12 13:41:13 +00:00
|
|
|
$this->info['text-decoration-line'] = new HTMLPurifier_AttrDef_Enum(
|
|
|
|
['none', 'underline', 'overline', 'line-through', 'initial', 'inherit']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->info['text-decoration-style'] = new HTMLPurifier_AttrDef_Enum(
|
|
|
|
['solid', 'double', 'dotted', 'dashed', 'wavy', 'initial', 'inherit']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->info['text-decoration-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
|
|
|
|
$this->info['text-decoration-thickness'] = new HTMLPurifier_AttrDef_CSS_Composite([
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto', 'from-font', 'initial', 'inherit'])
|
|
|
|
]);
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['font-family'] = new HTMLPurifier_AttrDef_CSS_FontFamily();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-13 16:52:31 +00:00
|
|
|
// this could use specialized code
|
|
|
|
$this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'normal',
|
|
|
|
'bold',
|
|
|
|
'bolder',
|
|
|
|
'lighter',
|
|
|
|
'100',
|
|
|
|
'200',
|
|
|
|
'300',
|
|
|
|
'400',
|
|
|
|
'500',
|
|
|
|
'600',
|
|
|
|
'700',
|
|
|
|
'800',
|
|
|
|
'900'
|
2023-01-12 13:41:13 +00:00
|
|
|
],
|
2013-07-16 11:56:14 +00:00
|
|
|
false
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-27 00:11:13 +00:00
|
|
|
// MUST be called after other font properties, as it references
|
|
|
|
// a CSSDefinition object
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['font'] = new HTMLPurifier_AttrDef_CSS_Font($config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-27 00:49:34 +00:00
|
|
|
// same here
|
|
|
|
$this->info['border'] =
|
2008-12-06 07:28:20 +00:00
|
|
|
$this->info['border-bottom'] =
|
|
|
|
$this->info['border-top'] =
|
|
|
|
$this->info['border-left'] =
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->info['border-right'] = new HTMLPurifier_AttrDef_CSS_Border($config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['collapse', 'separate']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['top', 'bottom']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['auto', 'fixed']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['vertical-align'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'baseline',
|
|
|
|
'sub',
|
|
|
|
'super',
|
|
|
|
'top',
|
|
|
|
'text-top',
|
|
|
|
'middle',
|
|
|
|
'bottom',
|
|
|
|
'text-bottom'
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage()
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-09-03 15:16:33 +00:00
|
|
|
$this->info['border-spacing'] = new HTMLPurifier_AttrDef_CSS_Multiple(new HTMLPurifier_AttrDef_CSS_Length(), 2);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2012-06-16 21:10:36 +00:00
|
|
|
// These CSS properties don't work on many browsers, but we live
|
|
|
|
// in THE FUTURE!
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['nowrap', 'normal', 'pre', 'pre-wrap', 'pre-line']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
if ($config->get('CSS.Proprietary')) {
|
2007-12-16 23:16:45 +00:00
|
|
|
$this->doSetupProprietary($config);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
if ($config->get('CSS.AllowTricky')) {
|
2008-02-25 22:05:49 +00:00
|
|
|
$this->doSetupTricky($config);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2010-11-12 18:45:03 +00:00
|
|
|
if ($config->get('CSS.Trusted')) {
|
|
|
|
$this->doSetupTrusted($config);
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$allow_important = $config->get('CSS.AllowImportant');
|
2008-02-25 21:58:17 +00:00
|
|
|
// wrap all attr-defs with decorator that handles !important
|
|
|
|
foreach ($this->info as $k => $v) {
|
|
|
|
$this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-30 21:44:16 +00:00
|
|
|
$this->setupConfigStuff($config);
|
2007-12-16 23:16:45 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
*/
|
|
|
|
protected function doSetupProprietary($config)
|
|
|
|
{
|
2007-12-16 23:16:45 +00:00
|
|
|
// Internet Explorer only scrollbar colors
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['scrollbar-arrow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
$this->info['scrollbar-base-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
$this->info['scrollbar-darkshadow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
$this->info['scrollbar-face-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
$this->info['scrollbar-highlight-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
|
|
$this->info['scrollbar-shadow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2014-08-31 08:23:58 +00:00
|
|
|
// vendor specific prefixes of opacity
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['-moz-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
|
|
|
$this->info['-khtml-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-12-16 23:16:45 +00:00
|
|
|
// only opacity, for now
|
|
|
|
$this->info['filter'] = new HTMLPurifier_AttrDef_CSS_Filter();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2012-10-11 18:39:52 +00:00
|
|
|
// more CSS3
|
|
|
|
$this->info['page-break-after'] =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['page-break-before'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'auto',
|
|
|
|
'always',
|
|
|
|
'avoid',
|
|
|
|
'left',
|
|
|
|
'right'
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2023-01-12 13:41:13 +00:00
|
|
|
$this->info['page-break-inside'] = new HTMLPurifier_AttrDef_Enum(['auto', 'avoid']);
|
2012-10-11 18:39:52 +00:00
|
|
|
|
2016-07-01 02:22:13 +00:00
|
|
|
$border_radius = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2016-07-01 02:22:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(true), // disallow negative
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Length('0') // disallow negative
|
2023-01-12 13:41:13 +00:00
|
|
|
]);
|
2016-07-01 02:22:13 +00:00
|
|
|
|
|
|
|
$this->info['border-top-left-radius'] =
|
|
|
|
$this->info['border-top-right-radius'] =
|
|
|
|
$this->info['border-bottom-right-radius'] =
|
|
|
|
$this->info['border-bottom-left-radius'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_radius, 2);
|
|
|
|
// TODO: support SLASH syntax
|
|
|
|
$this->info['border-radius'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_radius, 4);
|
|
|
|
|
2006-08-12 20:22:09 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
*/
|
|
|
|
protected function doSetupTricky($config)
|
|
|
|
{
|
|
|
|
$this->info['display'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
'inline',
|
|
|
|
'block',
|
|
|
|
'list-item',
|
|
|
|
'run-in',
|
|
|
|
'compact',
|
|
|
|
'marker',
|
|
|
|
'table',
|
|
|
|
'inline-block',
|
|
|
|
'inline-table',
|
|
|
|
'table-row-group',
|
|
|
|
'table-header-group',
|
|
|
|
'table-footer-group',
|
|
|
|
'table-row',
|
|
|
|
'table-column-group',
|
|
|
|
'table-column',
|
|
|
|
'table-cell',
|
|
|
|
'table-caption',
|
|
|
|
'none'
|
2023-01-12 13:41:13 +00:00
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
|
|
|
$this->info['visibility'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['visible', 'hidden', 'collapse']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2023-01-12 13:41:13 +00:00
|
|
|
$this->info['overflow'] = new HTMLPurifier_AttrDef_Enum(['visible', 'hidden', 'auto', 'scroll']);
|
2014-08-31 08:23:58 +00:00
|
|
|
$this->info['opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
2008-02-25 22:05:49 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
*/
|
|
|
|
protected function doSetupTrusted($config)
|
|
|
|
{
|
|
|
|
$this->info['position'] = new HTMLPurifier_AttrDef_Enum(
|
2023-01-12 13:41:13 +00:00
|
|
|
['static', 'relative', 'absolute', 'fixed']
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2010-11-12 18:45:03 +00:00
|
|
|
$this->info['top'] =
|
|
|
|
$this->info['left'] =
|
|
|
|
$this->info['right'] =
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->info['bottom'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
|
|
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto']),
|
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
|
|
|
$this->info['z-index'] = new HTMLPurifier_AttrDef_CSS_Composite(
|
2023-01-12 13:41:13 +00:00
|
|
|
[
|
2013-07-16 11:56:14 +00:00
|
|
|
new HTMLPurifier_AttrDef_Integer(),
|
2023-01-12 13:41:13 +00:00
|
|
|
new HTMLPurifier_AttrDef_Enum(['auto']),
|
|
|
|
]
|
2013-07-16 11:56:14 +00:00
|
|
|
);
|
2010-11-12 18:45:03 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-30 21:44:16 +00:00
|
|
|
/**
|
|
|
|
* Performs extra config-based processing. Based off of
|
|
|
|
* HTMLPurifier_HTMLDefinition.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param HTMLPurifier_Config $config
|
2008-03-30 21:44:16 +00:00
|
|
|
* @todo Refactor duplicate elements into common class (probably using
|
|
|
|
* composition, not inheritance).
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
protected function setupConfigStuff($config)
|
|
|
|
{
|
2008-03-30 21:44:16 +00:00
|
|
|
// setup allowed elements
|
2013-07-16 11:56:14 +00:00
|
|
|
$support = "(for information on implementing this, see the " .
|
|
|
|
"support forums) ";
|
2010-09-04 06:59:03 +00:00
|
|
|
$allowed_properties = $config->get('CSS.AllowedProperties');
|
|
|
|
if ($allowed_properties !== null) {
|
2008-03-30 21:44:16 +00:00
|
|
|
foreach ($this->info as $name => $d) {
|
2013-07-16 11:56:14 +00:00
|
|
|
if (!isset($allowed_properties[$name])) {
|
|
|
|
unset($this->info[$name]);
|
|
|
|
}
|
2010-09-04 06:59:03 +00:00
|
|
|
unset($allowed_properties[$name]);
|
2008-03-30 21:44:16 +00:00
|
|
|
}
|
|
|
|
// emit errors
|
2010-09-04 06:59:03 +00:00
|
|
|
foreach ($allowed_properties as $name => $d) {
|
2008-03-30 21:44:16 +00:00
|
|
|
// :TODO: Is this htmlspecialchars() call really necessary?
|
|
|
|
$name = htmlspecialchars($name);
|
|
|
|
trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING);
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2010-09-04 06:59:03 +00:00
|
|
|
$forbidden_properties = $config->get('CSS.ForbiddenProperties');
|
|
|
|
if ($forbidden_properties !== null) {
|
|
|
|
foreach ($this->info as $name => $d) {
|
|
|
|
if (isset($forbidden_properties[$name])) {
|
|
|
|
unset($this->info[$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-30 21:44:16 +00:00
|
|
|
}
|
2006-08-12 20:22:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|