root/afridex/plugins/Flutter/purifier_lib/HTMLPurifier/AttrDef/CSS/ListStyle.php

Revision 21, 2.4 kB (checked in by admin, 18 years ago)
Line 
1<?php
2
3/**
4 * Validates shorthand CSS property list-style.
5 * @warning Does not support url tokens that have internal spaces.
6 */
7class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
8{
9   
10    /**
11     * Local copy of component validators.
12     * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
13     */
14    protected $info;
15   
16    public function __construct($config) {
17        $def = $config->getCSSDefinition();
18        $this->info['list-style-type']     = $def->info['list-style-type'];
19        $this->info['list-style-position'] = $def->info['list-style-position'];
20        $this->info['list-style-image'] = $def->info['list-style-image'];
21    }
22   
23    public function validate($string, $config, $context) {
24       
25        // regular pre-processing
26        $string = $this->parseCDATA($string);
27        if ($string === '') return false;
28       
29        // assumes URI doesn't have spaces in it
30        $bits = explode(' ', strtolower($string)); // bits to process
31       
32        $caught = array();
33        $caught['type']     = false;
34        $caught['position'] = false;
35        $caught['image']    = false;
36       
37        $i = 0; // number of catches
38        $none = false;
39       
40        foreach ($bits as $bit) {
41            if ($i >= 3) return; // optimization bit
42            if ($bit === '') continue;
43            foreach ($caught as $key => $status) {
44                if ($status !== false) continue;
45                $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
46                if ($r === false) continue;
47                if ($r === 'none') {
48                    if ($none) continue;
49                    else $none = true;
50                    if ($key == 'image') continue;
51                }
52                $caught[$key] = $r;
53                $i++;
54                break;
55            }
56        }
57       
58        if (!$i) return false;
59       
60        $ret = array();
61       
62        // construct type
63        if ($caught['type']) $ret[] = $caught['type'];
64       
65        // construct image
66        if ($caught['image']) $ret[] = $caught['image'];
67       
68        // construct position
69        if ($caught['position']) $ret[] = $caught['position'];
70       
71        if (empty($ret)) return false;
72        return implode(' ', $ret);
73       
74    }
75   
76}
77
Note: See TracBrowser for help on using the browser.