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