[FEATURE] Custom attribute name and multiple values for meta tags 20/40120/17
authorAlexander Kontos <info@mediafabrica.de>
Thu, 11 Jun 2015 22:32:23 +0000 (00:32 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 18 Jun 2015 11:16:49 +0000 (13:16 +0200)
To support a broader range of possible meta tags we need a specify
the used attribute name. Also now it is possible to ad the same
meta tag with different values.

Resolves: #67360
Releases: master
Change-Id: Ic8f8e03a7b137302af6613edfbe7e89a50e25e12
Reviewed-on: http://review.typo3.org/40120
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-67360-CustomAttributeNameAndMultipleValuesForMetaTags.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageGenerator.php
typo3/sysext/frontend/Tests/Unit/Page/PageGeneratorTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-67360-CustomAttributeNameAndMultipleValuesForMetaTags.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-67360-CustomAttributeNameAndMultipleValuesForMetaTags.rst
new file mode 100644 (file)
index 0000000..f501b96
--- /dev/null
@@ -0,0 +1,53 @@
+=========================================================================
+Feature: #67360 - Custom attribute name and multiple values for meta tags
+=========================================================================
+
+Description
+===========
+
+`page.meta` is extented to support different attribute names like `property` used for OG tags. You may also supply
+multiple values for one name, which results in multiple meta tags with the same name to be rendered.
+
+See http://ogp.me/ for more information about the Open Graph protocol and its properties.
+
+.. code-block:: typoscript
+
+    page {
+        meta {
+            X-UA-Compatible = IE=edge,chrome=1
+            X-UA-Compatible.attribute = http-equiv
+
+            keywords = TYPO3
+
+            og:site_name = TYPO3
+            og:site_name.attribute = property
+
+            description = Inspiring people to share Normal
+
+            dc\.description = Inspiring people to share [DC tags]
+
+            og:description = Inspiring people to share [OpenGraph]
+            og:description.attribute = property
+
+            og:locale = en_GB
+            og:locale.attribute = property
+
+            og:locale:alternate {
+                attribute = property
+                value {
+                    1 = fr_FR
+                    2 = de_DE
+                }
+            }
+
+            refresh = 5; url=http://example.com/
+            refresh.attribute = http-equiv
+
+        }
+    }
+
+
+Impact
+======
+
+Meta tags with a different attribute name are supported now like the Open Graph meta tags.
\ No newline at end of file
index 632b4b2..2d08abe 100644 (file)
@@ -1195,15 +1195,28 @@ class PageGenerator {
                        if (is_array($properties)) {
                                $nodeValue = isset($properties['_typoScriptNodeValue']) ? $properties['_typoScriptNodeValue'] : '';
                                $value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']));
+                               if ($value === '' && !empty($properties['value'])) {
+                                       $value = $properties['value'];
+                               }
                        } else {
                                $value = $properties;
                        }
-                       if ($value !== '') {
-                               $attribute = 'name';
-                               if ( (is_array($properties) && !empty($properties['httpEquivalent'])) || strtolower($key) === 'refresh') {
-                                       $attribute = 'http-equiv';
+
+                       $attribute = 'name';
+                       if ((is_array($properties) && !empty($properties['httpEquivalent'])) || strtolower($key) === 'refresh') {
+                               $attribute = 'http-equiv';
+                       }
+                       if (is_array($properties) && !empty($properties['attribute'])) {
+                               $attribute = $properties['attribute'];
+                       }
+
+                       if (!is_array($value)) {
+                               $value = (array)$value;
+                       }
+                       foreach ($value as $subValue) {
+                               if (trim($subValue) !== '') {
+                                       $metaTags[] = '<meta ' . $attribute . '="' . $key . '" content="' . htmlspecialchars($subValue) . '"' . $endingSlash . '>';
                                }
-                               $metaTags[] = '<meta ' . $attribute . '="' . $key . '" content="' . htmlspecialchars($value) . '"' . $endingSlash . '>';
                        }
                }
                return $metaTags;
index 2aae33c..b3a655c 100644 (file)
@@ -70,7 +70,7 @@ class PageGeneratorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'meta with nested stdWrap' => array(
                                array(
                                        'author' => 'Markus ',
-                                   'author.' => array('stdWrap.' => array('wrap' => '|Klein'))
+                                       'author.' => array('stdWrap.' => array('wrap' => '|Klein'))
                                ),
                                FALSE,
                                array(
@@ -81,15 +81,15 @@ class PageGeneratorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'httpEquivalent meta' => array(
                                array(
                                        'X-UA-Compatible' => 'IE=edge,chrome=1',
-                                   'X-UA-Compatible.' => array('httpEquivalent' => 1)
+                                       'X-UA-Compatible.' => array('httpEquivalent' => 1)
                                ),
                                FALSE,
-                           array(
-                                   '<meta name="generator" content="TYPO3 CMS">',
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
                                        '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'
-                           )
+                               )
                        ),
-                   'httpEquivalent meta xhtml' => array(
+                       'httpEquivalent meta xhtml' => array(
                                array(
                                        'X-UA-Compatible' => 'IE=edge,chrome=1',
                                        'X-UA-Compatible.' => array('httpEquivalent' => 1)
@@ -99,10 +99,32 @@ class PageGeneratorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        '<meta name="generator" content="TYPO3 CMS" />',
                                        '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />'
                                )
-                   ),
-                   'refresh meta' => array(
+                       ),
+                       'httpEquivalent meta xhtml new notation' => array(
+                               array(
+                                       'X-UA-Compatible' => 'IE=edge,chrome=1',
+                                       'X-UA-Compatible.' => array('attribute' => 'http-equiv')
+                               ),
+                               TRUE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS" />',
+                                       '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />'
+                               )
+                       ),
+                       'refresh meta' => array(
+                               array(
+                                       'refresh' => '10',
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta http-equiv="refresh" content="10">',
+                               )
+                       ),
+                       'refresh meta new notation' => array(
                                array(
                                        'refresh' => '10',
+                                       'refresh.' => array('attribute' => 'http-equiv')
                                ),
                                FALSE,
                                array(
@@ -110,26 +132,102 @@ class PageGeneratorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        '<meta http-equiv="refresh" content="10">',
                                )
                        ),
-                   'meta with dot' => array(
-                           array(
-                                   'DC.author' => 'Markus Klein',
-                           ),
-                           FALSE,
-                           array(
-                                   '<meta name="generator" content="TYPO3 CMS">',
-                                   '<meta name="DC.author" content="Markus Klein">',
-                           )
-                   ),
-                   'meta with colon' => array(
-                           array(
-                                   'OG:title' => 'Magic Tests',
-                           ),
-                           FALSE,
-                           array(
-                                   '<meta name="generator" content="TYPO3 CMS">',
-                                   '<meta name="OG:title" content="Magic Tests">',
-                           )
-                   ),
+                       'refresh meta new notation wins form old' => array(
+                               array(
+                                       'refresh' => '10',
+                                       'refresh.' => array('attribute' => 'http-equiv-new')
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta http-equiv-new="refresh" content="10">',
+                               )
+                       ),
+                       'meta with dot' => array(
+                               array(
+                                       'DC.author' => 'Markus Klein',
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta name="DC.author" content="Markus Klein">',
+                               )
+                       ),
+                       'meta with colon' => array(
+                               array(
+                                       'OG:title' => 'Magic Tests',
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta name="OG:title" content="Magic Tests">',
+                               )
+                       ),
+                       'different attribute name' => array(
+                               array(
+                                       'og:site_title' => 'My TYPO3 site',
+                                       'og:site_title.' => array('attribute' => 'property'),
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta property="og:site_title" content="My TYPO3 site">',
+                               )
+                       ),
+                       'multi value attribute name' => array(
+                               array(
+                                       'og:locale:alternate.' => array(
+                                               'attribute' => 'property',
+                                               'value' => array(
+                                                       10 => 'nl_NL',
+                                                       20 => 'de_DE',
+                                               )
+                                       ),
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta property="og:locale:alternate" content="nl_NL">',
+                                       '<meta property="og:locale:alternate" content="de_DE">',
+                               )
+                       ),
+                       'multi value attribute name (empty values are skipped)' => array(
+                               array(
+                                       'og:locale:alternate.' => array(
+                                               'attribute' => 'property',
+                                               'value' => array(
+                                                       10 => 'nl_NL',
+                                                       20 => '',
+                                                       30 => 'de_DE',
+                                               )
+                                       ),
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta property="og:locale:alternate" content="nl_NL">',
+                                       '<meta property="og:locale:alternate" content="de_DE">',
+                               )
+                       ),
+                       'meta with empty string value' => array(
+                               array(
+                                       'custom:key' => '',
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                               )
+                       ),
+                       'meta with 0 value' => array(
+                               array(
+                                       'custom:key' => '0',
+                               ),
+                               FALSE,
+                               array(
+                                       '<meta name="generator" content="TYPO3 CMS">',
+                                       '<meta name="custom:key" content="0">',
+                               )
+                       ),
                );
        }