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