1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class QRMarkup |
4
|
|
|
* |
5
|
|
|
* @created 17.12.2016 |
6
|
|
|
* @author Smiley <[email protected]> |
7
|
|
|
* @copyright 2016 Smiley |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace chillerlan\QRCode\Output; |
12
|
|
|
|
13
|
|
|
use function is_string, preg_match, strip_tags, trim; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract for markup types: HTML, SVG, ... XML anyone? |
17
|
|
|
*/ |
18
|
|
|
abstract class QRMarkup extends QROutputAbstract{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* note: we're not necessarily validating the several values, just checking the general syntax |
22
|
|
|
* note: css4 colors are not included |
23
|
|
|
* |
24
|
|
|
* @todo: XSS proof |
25
|
|
|
* |
26
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public static function moduleValueIsValid($value):bool{ |
30
|
|
|
|
31
|
|
|
if(!is_string($value)){ |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$value = trim(strip_tags($value), " '\"\r\n\t"); |
36
|
|
|
|
37
|
|
|
// hex notation |
38
|
|
|
// #rgb(a) |
39
|
|
|
// #rrggbb(aa) |
40
|
|
|
if(preg_match('/^#([\da-f]{3}){1,2}$|^#([\da-f]{4}){1,2}$/i', $value)){ |
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// css: hsla/rgba(...values) |
45
|
|
|
if(preg_match('#^(hsla?|rgba?)\([\d .,%/]+\)$#i', $value)){ |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// predefined css color |
50
|
|
|
if(preg_match('/^[a-z]+$/i', $value)){ |
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritDoc |
59
|
|
|
*/ |
60
|
|
|
protected function prepareModuleValue($value):string{ |
61
|
|
|
return trim(strip_tags($value), " '\"\r\n\t"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritDoc |
66
|
|
|
*/ |
67
|
|
|
protected function getDefaultModuleValue(bool $isDark):string{ |
68
|
|
|
return ($isDark) ? $this->options->markupDark : $this->options->markupLight; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function dump(string $file = null):string{ |
75
|
|
|
$data = $this->createMarkup($file !== null); |
76
|
|
|
|
77
|
|
|
$this->saveToFile($data, $file); |
78
|
|
|
|
79
|
|
|
return $data; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* returns a string with all css classes for the current element |
84
|
|
|
*/ |
85
|
|
|
protected function getCssClass(int $M_TYPE):string{ |
|
|
|
|
86
|
|
|
return $this->options->cssClass; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* |
91
|
|
|
*/ |
92
|
|
|
abstract protected function createMarkup(bool $saveToFile):string; |
93
|
|
|
} |
94
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.