PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / sabberworm / php-css-parser / src / Property / Selector.php
independent-analytics / vendor / sabberworm / php-css-parser / src / Property Last commit date
AtRule.php 3 years ago CSSNamespace.php 3 years ago Charset.php 3 years ago Import.php 3 years ago KeyframeSelector.php 3 years ago Selector.php 3 years ago
Selector.php
129 lines
1 <?php
2
3 namespace IAWP\Sabberworm\CSS\Property;
4
5 /**
6 * Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this
7 * class.
8 */
9 class Selector
10 {
11 /**
12 * regexp for specificity calculations
13 *
14 * @var string
15 */
16 const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
17 (\\.[\\w]+) # classes
18 |
19 \\[(\\w+) # attributes
20 |
21 (\\:( # pseudo classes
22 link|visited|active
23 |hover|focus
24 |lang
25 |target
26 |enabled|disabled|checked|indeterminate
27 |root
28 |nth-child|nth-last-child|nth-of-type|nth-last-of-type
29 |first-child|last-child|first-of-type|last-of-type
30 |only-child|only-of-type
31 |empty|contains
32 ))
33 /ix';
34 /**
35 * regexp for specificity calculations
36 *
37 * @var string
38 */
39 const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
40 ((^|[\\s\\+\\>\\~]+)[\\w]+ # elements
41 |
42 \\:{1,2}( # pseudo-elements
43 after|before|first-letter|first-line|selection
44 ))
45 /ix';
46 /**
47 * regexp for specificity calculations
48 *
49 * @var string
50 */
51 const SELECTOR_VALIDATION_RX = '/
52 ^(
53 (?:
54 [a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*="\'~\\[\\]()\\-\\s\\.:#+>]* # any sequence of valid unescaped characters
55 (?:\\\\.)? # a single escaped character
56 (?:([\'"]).*?(?<!\\\\)\\2)? # a quoted text like [id="example"]
57 )*
58 )$
59 /ux';
60 /**
61 * @var string
62 */
63 private $sSelector;
64 /**
65 * @var int|null
66 */
67 private $iSpecificity;
68 /**
69 * @param string $sSelector
70 *
71 * @return bool
72 */
73 public static function isValid($sSelector)
74 {
75 return \preg_match(static::SELECTOR_VALIDATION_RX, $sSelector);
76 }
77 /**
78 * @param string $sSelector
79 * @param bool $bCalculateSpecificity
80 */
81 public function __construct($sSelector, $bCalculateSpecificity = \false)
82 {
83 $this->setSelector($sSelector);
84 if ($bCalculateSpecificity) {
85 $this->getSpecificity();
86 }
87 }
88 /**
89 * @return string
90 */
91 public function getSelector()
92 {
93 return $this->sSelector;
94 }
95 /**
96 * @param string $sSelector
97 *
98 * @return void
99 */
100 public function setSelector($sSelector)
101 {
102 $this->sSelector = \trim($sSelector);
103 $this->iSpecificity = null;
104 }
105 /**
106 * @return string
107 */
108 public function __toString()
109 {
110 return $this->getSelector();
111 }
112 /**
113 * @return int
114 */
115 public function getSpecificity()
116 {
117 if ($this->iSpecificity === null) {
118 $a = 0;
119 /// @todo should exclude \# as well as "#"
120 $aMatches = null;
121 $b = \substr_count($this->sSelector, '#');
122 $c = \preg_match_all(self::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX, $this->sSelector, $aMatches);
123 $d = \preg_match_all(self::ELEMENTS_AND_PSEUDO_ELEMENTS_RX, $this->sSelector, $aMatches);
124 $this->iSpecificity = $a * 1000 + $b * 100 + $c * 10 + $d;
125 }
126 return $this->iSpecificity;
127 }
128 }
129