‪TYPO3CMS  9.5
GenericMetaTagManager.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
24 {
30  protected ‪$subPropertySeparator = ':';
31 
37  protected ‪$properties = [];
38 
48  public function ‪addProperty(string $property, string $content, array $subProperties = [], bool $replace = false, string $type = 'name')
49  {
50  $property = strtolower($property);
51  $type = strtolower($type) ?: 'name';
52 
53  if ($replace) {
54  $this->‪removeProperty($property, $type);
55  }
56 
57  $this->properties[$property][$type][] = [
58  'content' => $content,
59  'subProperties' => $subProperties
60  ];
61  }
62 
70  public function ‪getProperty(string $property, string $type = 'name'): array
71  {
72  $property = strtolower($property);
73  $type = strtolower($type) ?: 'name';
74 
75  if (!empty($this->properties[$property][$type])) {
76  return $this->properties[$property][$type];
77  }
78  return [];
79  }
80 
85  public function ‪getAllHandledProperties(): array
86  {
87  return [];
88  }
89 
95  public function ‪renderAllProperties(): string
96  {
97  $metatags = [];
98  foreach (array_keys($this->properties) as $property) {
99  $metatags[] = $this->‪renderProperty($property);
100  }
101 
102  return implode(PHP_EOL, $metatags);
103  }
104 
111  public function ‪renderProperty(string $property): string
112  {
113  $property = strtolower($property);
114 
115  $metaTags = [];
116  foreach ((array)$this->properties[$property] as $type => $propertyItems) {
117  foreach ($propertyItems as $propertyItem) {
118  $metaTags[] = '<meta ' .
119  htmlspecialchars($type) . '="' . htmlspecialchars($property) . '" ' .
120  'content="' . htmlspecialchars($propertyItem['content']) . '" />';
121 
122  if (!count($propertyItem['subProperties'])) {
123  continue;
124  }
125  foreach ($propertyItem['subProperties'] as $subProperty => $value) {
126  $metaTags[] = '<meta ' .
127  htmlspecialchars($type) . '="' . htmlspecialchars($property . $this->subPropertySeparator . $subProperty) . '" ' .
128  'content="' . htmlspecialchars((string)$value) . '" />';
129  }
130  }
131  }
132 
133  return implode(PHP_EOL, $metaTags);
134  }
135 
143  public function ‪removeProperty(string $property, string $type = '')
144  {
145  if (!empty($type)) {
146  unset($this->properties[$property][$type]);
147  } else {
148  unset($this->properties[$property]);
149  }
150  }
151 
155  public function ‪removeAllProperties()
156  {
157  $this->properties = [];
158  }
159 
164  public function ‪canHandleProperty(string $property): bool
165  {
166  return true;
167  }
168 }
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\renderAllProperties
‪string renderAllProperties()
Definition: GenericMetaTagManager.php:93
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\canHandleProperty
‪bool canHandleProperty(string $property)
Definition: GenericMetaTagManager.php:162
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\renderProperty
‪string renderProperty(string $property)
Definition: GenericMetaTagManager.php:109
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\$properties
‪array $properties
Definition: GenericMetaTagManager.php:35
‪TYPO3\CMS\Core\MetaTag\MetaTagManagerInterface
Definition: MetaTagManagerInterface.php:20
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\addProperty
‪addProperty(string $property, string $content, array $subProperties=[], bool $replace=false, string $type='name')
Definition: GenericMetaTagManager.php:46
‪TYPO3\CMS\Core\MetaTag
Definition: AbstractMetaTagManager.php:4
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\getProperty
‪array getProperty(string $property, string $type='name')
Definition: GenericMetaTagManager.php:68
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\$subPropertySeparator
‪string $subPropertySeparator
Definition: GenericMetaTagManager.php:29
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager
Definition: GenericMetaTagManager.php:24
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\removeAllProperties
‪removeAllProperties()
Definition: GenericMetaTagManager.php:153
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\removeProperty
‪removeProperty(string $property, string $type='')
Definition: GenericMetaTagManager.php:141
‪TYPO3\CMS\Core\MetaTag\GenericMetaTagManager\getAllHandledProperties
‪array getAllHandledProperties()
Definition: GenericMetaTagManager.php:83