1 | <?php |
||
2 | /** |
||
3 | * SEOmatic plugin for Craft CMS |
||
4 | * |
||
5 | * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
||
6 | * and flexible |
||
7 | * |
||
8 | * @link https://nystudio107.com |
||
9 | * @copyright Copyright (c) 2017 nystudio107 |
||
10 | */ |
||
11 | |||
12 | namespace nystudio107\seomatic\base; |
||
13 | |||
14 | use Craft; |
||
15 | use nystudio107\seomatic\helpers\MetaValue as MetaValueHelper; |
||
16 | use function is_string; |
||
17 | |||
18 | /** |
||
19 | * @author nystudio107 |
||
20 | * @package Seomatic |
||
21 | * @since 3.0.0 |
||
22 | */ |
||
23 | abstract class VarsModel extends FluentModel |
||
24 | { |
||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | public function init(): void |
||
29 | { |
||
30 | parent::init(); |
||
31 | // For all the emojis |
||
32 | $attributes = $this->attributes(); |
||
33 | if ($attributes !== null) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
34 | foreach ($attributes as $attribute) { |
||
35 | if (is_string($this->$attribute)) { |
||
36 | $this->$attribute = html_entity_decode($this->$attribute, ENT_NOQUOTES, 'UTF-8'); |
||
37 | } |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Return the parsed value of a single property |
||
44 | * |
||
45 | * @param string $property |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function parsedValue(string $property): string |
||
50 | { |
||
51 | $result = ''; |
||
52 | |||
53 | if ($this->canGetProperty($property)) { |
||
54 | $result = MetaValueHelper::parseString($this->$property); |
||
55 | } |
||
56 | |||
57 | return (string)$result; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Parse the model properties |
||
62 | */ |
||
63 | public function parseProperties() |
||
64 | { |
||
65 | Craft::beginProfile('VarsModel::parseProperties', __METHOD__); |
||
66 | // Parse the meta global vars |
||
67 | $attributes = $this->getAttributes(); |
||
68 | MetaValueHelper::parseArray($attributes); |
||
69 | $this->setAttributes($attributes); |
||
70 | Craft::endProfile('VarsModel::parseProperties', __METHOD__); |
||
71 | } |
||
72 | } |
||
73 |