1 | <?php |
||
12 | class ExternalURLField extends TextField |
||
13 | { |
||
14 | /** |
||
15 | * Default configuration |
||
16 | * |
||
17 | * URL validation regular expression was sourced from |
||
18 | * @see https://gist.github.com/dperini/729294 |
||
19 | * @var array |
||
20 | */ |
||
21 | private static $default_config = array( |
||
22 | 'defaultparts' => array( |
||
23 | 'scheme' => 'http' |
||
24 | ), |
||
25 | 'removeparts' => array( |
||
26 | 'scheme' => false, |
||
27 | 'user' => true, |
||
28 | 'pass' => true, |
||
29 | 'host' => false, |
||
30 | 'port' => false, |
||
31 | 'path' => false, |
||
32 | 'query' => false, |
||
33 | 'fragment' => false |
||
34 | ), |
||
35 | 'html5validation' => true, |
||
36 | 'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu' |
||
37 | ); |
||
38 | |||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $config; |
||
43 | |||
44 | 4 | public function __construct($name, $title = null, $value = null) |
|
50 | |||
51 | public function Type() |
||
55 | |||
56 | /** |
||
57 | * @param string $name |
||
58 | * @param mixed $val |
||
59 | */ |
||
60 | 1 | public function setConfig($name, $val = null) |
|
80 | |||
81 | /** |
||
82 | * @param String $name Optional, returns the whole configuration array if empty |
||
83 | * @return mixed|array |
||
84 | */ |
||
85 | 1 | public function getConfig($name = null) |
|
93 | |||
94 | /** |
||
95 | * Set additional attributes |
||
96 | * @return array Attributes |
||
97 | */ |
||
98 | public function getAttributes() |
||
115 | |||
116 | /** |
||
117 | * Rebuild url on save |
||
118 | * @param string $url |
||
119 | */ |
||
120 | 2 | public function setValue($url) |
|
127 | |||
128 | /** |
||
129 | * Add config scheme, if missing. |
||
130 | * Remove the parts of the url we don't want. |
||
131 | * Set any defaults, if missing. |
||
132 | * Remove any trailing slash, and rebuild. |
||
133 | * @return string |
||
134 | */ |
||
135 | 2 | protected function rebuildURL($url) |
|
160 | |||
161 | /** |
||
162 | * Server side validation, using a regular expression. |
||
163 | */ |
||
164 | 1 | public function validate($validator) |
|
178 | } |
||
179 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: