]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / AttrDef / HTML / Nmtokens.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Validates contents based on NMTOKENS attribute type.\r
5 */\r
6class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef\r
7{\r
8\r
9 /**\r
10 * @param string $string\r
11 * @param HTMLPurifier_Config $config\r
12 * @param HTMLPurifier_Context $context\r
13 * @return bool|string\r
14 */\r
15 public function validate($string, $config, $context)\r
16 {\r
17 $string = trim($string);\r
18\r
19 // early abort: '' and '0' (strings that convert to false) are invalid\r
20 if (!$string) {\r
21 return false;\r
22 }\r
23\r
24 $tokens = $this->split($string, $config, $context);\r
25 $tokens = $this->filter($tokens, $config, $context);\r
26 if (empty($tokens)) {\r
27 return false;\r
28 }\r
29 return implode(' ', $tokens);\r
30 }\r
31\r
32 /**\r
33 * Splits a space separated list of tokens into its constituent parts.\r
34 * @param string $string\r
35 * @param HTMLPurifier_Config $config\r
36 * @param HTMLPurifier_Context $context\r
37 * @return array\r
38 */\r
39 protected function split($string, $config, $context)\r
40 {\r
41 // OPTIMIZABLE!\r
42 // do the preg_match, capture all subpatterns for reformulation\r
43\r
44 // we don't support U+00A1 and up codepoints or\r
45 // escaping because I don't know how to do that with regexps\r
46 // and plus it would complicate optimization efforts (you never\r
47 // see that anyway).\r
48 $pattern = '/(?:(?<=\s)|\A)' . // look behind for space or string start\r
49 '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)' .\r
50 '(?:(?=\s)|\z)/'; // look ahead for space or string end\r
51 preg_match_all($pattern, $string, $matches);\r
52 return $matches[1];\r
53 }\r
54\r
55 /**\r
56 * Template method for removing certain tokens based on arbitrary criteria.\r
57 * @note If we wanted to be really functional, we'd do an array_filter\r
58 * with a callback. But... we're not.\r
59 * @param array $tokens\r
60 * @param HTMLPurifier_Config $config\r
61 * @param HTMLPurifier_Context $context\r
62 * @return array\r
63 */\r
64 protected function filter($tokens, $config, $context)\r
65 {\r
66 return $tokens;\r
67 }\r
68}\r
69\r
70// vim: et sw=4 sts=4\r