From f4fea21fa5cfbfd04c27a1bf2578cc8c9662414c Mon Sep 17 00:00:00 2001 From: Tobias Pinnekamp Date: Tue, 26 Jul 2016 12:35:28 +0200 Subject: [PATCH 01/13] Fix page overlay bug This fixes the page overlay bug #23 I guess. The changes to composer.json can be ignored. I had to make them to temporarily integrate my fork into our project. The problem with the page overlay was, that $this->cObj->data only contains the information of the current database record, but without being overlayed. The $GLOBALS['TSFE']->page is the way to go for all fields. Additionally fetching the file relations have to be done from pages_language_overlay if not in default language. Therefore I introduced two new variables for fetching file relations based on the curreent sys_language_uid. This is only tested on TYPO3 7.6.9 but I think it should work on every other supported version. --- Classes/Service/OgRendererService.php | 543 +++++++++++++------------- ext_tables.php | 3 +- 2 files changed, 276 insertions(+), 270 deletions(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 95360e4..8cd31de 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -2,32 +2,34 @@ namespace Heilmann\JhOpengraphprotocol\Service; /*************************************************************** -* Copyright notice -* -* (c) 2014-2016 Jonathan Heilmann -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ + * Copyright notice + * + * (c) 2014-2016 Jonathan Heilmann + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Extbase\Utility\DebuggerUtility; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use TYPO3\CMS\Frontend\Page\PageRepository; /** * Class OgRendererService @@ -36,277 +38,280 @@ class OgRendererService implements \TYPO3\CMS\Core\SingletonInterface { - /** - * content Object - * - * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer - */ - public $cObj; + /** + * content Object + * + * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer + */ + public $cObj; - /** - * SignalSlotDispatcher - * - * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher - * @inject - */ - protected $signalSlotDispatcher; + /** + * SignalSlotDispatcher + * + * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher + * @inject + */ + protected $signalSlotDispatcher; - /** - * Main-function to render the Open Graph protocol content. - * - * @param string $content - * @param array $conf - * @return string - */ - public function main($content, $conf) - { - $extKey = 'tx_jhopengraphprotocol'; - $content = ''; - $og = array(); + /** + * Main-function to render the Open Graph protocol content. + * + * @param string $content + * @param array $conf + * @return string + */ + public function main($content, $conf) + { + $extKey = 'tx_jhopengraphprotocol'; + $content = ''; + $og = array(); - if ($this->signalSlotDispatcher == null) { - /* @var \TYPO3\CMS\Extbase\Object\ObjectManager */ - $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); - $this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); - } + if ($this->signalSlotDispatcher == null) { + /* @var \TYPO3\CMS\Extbase\Object\ObjectManager */ + $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); + $this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); + } - // 2013-04-22 kraftb@webconsulting.at - // Check if the tt_news "displaySingle" method has been called before - if (class_exists('tx_jhopengraphttnews_displaySingleHook')) { - $hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook'); - if ($hookObject->singleViewDisplayed()) - return $content; - } - if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) { - $hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class); - if ($hookObject->singleViewDisplayed()) - return $content; - } + // 2013-04-22 kraftb@webconsulting.at + // Check if the tt_news "displaySingle" method has been called before + if (class_exists('tx_jhopengraphttnews_displaySingleHook')) { + $hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook'); + if ($hookObject->singleViewDisplayed()) + return $content; + } + if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) { + $hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class); + if ($hookObject->singleViewDisplayed()) + return $content; + } - //if there has been no return, get og properties and render output + //if there has been no return, get og properties and render output - // Get title - if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtitle'])) { - $og['title'] = $this->cObj->data['tx_jhopengraphprotocol_ogtitle']; - } else { - $og['title'] = $GLOBALS['TSFE']->page['title']; - } - $og['title'] = htmlspecialchars($og['title']); + // Get title + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'])) { + $og['title'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']; + } else { + $og['title'] = $GLOBALS['TSFE']->page['title']; + } + $og['title'] = htmlspecialchars($og['title']); - // Get type - if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtype'])) { - $og['type'] = $this->cObj->data['tx_jhopengraphprotocol_ogtype']; - } else { - $og['type'] = $conf['type']; - } - $og['type'] = htmlspecialchars($og['type']); + // Get type + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'])) { + $og['type'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']; + } else { + $og['type'] = $conf['type']; + } + $og['type'] = htmlspecialchars($og['type']); - // Get image - /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */ - $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); - $fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { - // check if an image is given in page --> media, if not use default image - $fileObjects = $fileRepository->findByRelation('pages', 'media', $GLOBALS['TSFE']->id); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { - $imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']); - if (!empty($imageFileName)) { - $og['image'][] = $imageFileName; - } - } - } - - // Get url - $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); + $fileRelationPid = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?: $GLOBALS['TSFE']->id; + $fileRelationTable = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ? 'pages_language_overlay' : 'pages'; - // Get site_name - if (!empty($conf['sitename'])) { - $og['site_name'] = $conf['sitename']; - } else { - $og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle']; - } - $og['site_name'] = htmlspecialchars($og['site_name']); + // Get image + /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */ + $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); + $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'tx_jhopengraphprotocol_ogfalimages', $fileRelationPid); + if (count($fileObjects)) { + foreach ($fileObjects as $key => $fileObject) { + /** @var FileReference $fileObject */ + $og['image'][] = $fileObject; + } + } else { + // check if an image is given in page --> media, if not use default image + $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'media', $fileRelationPid); + if (count($fileObjects)) { + foreach ($fileObjects as $key => $fileObject) { + /** @var FileReference $fileObject */ + $og['image'][] = $fileObject; + } + } else { + $imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']); + if (!empty($imageFileName)) { + $og['image'][] = $imageFileName; + } + } + } - // Get description - if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogdescription'])) { - $og['description'] = $this->cObj->data['tx_jhopengraphprotocol_ogdescription']; - } else { - if (!empty($GLOBALS['TSFE']->page['description'])) { - $og['description'] = $GLOBALS['TSFE']->page['description']; - } else { - $og['description'] = $conf['description']; - } - } - $og['description'] = htmlspecialchars($og['description']); + // Get url + $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); - // Get locale - $localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']); - if (isset($localeParts[0])) { - $og['locale'] = str_replace('-', '_', $localeParts[0]); - } + // Get site_name + if (!empty($conf['sitename'])) { + $og['site_name'] = $conf['sitename']; + } else { + $og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle']; + } + $og['site_name'] = htmlspecialchars($og['site_name']); - // Signal to manipulate og-properties before header creation - $this->signalSlotDispatcher->dispatch( - __CLASS__, - 'beforeHeaderCreation', - array(&$og, $this->cObj) - ); + // Get description + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'])) { + $og['description'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription']; + } else { + if (!empty($GLOBALS['TSFE']->page['description'])) { + $og['description'] = $GLOBALS['TSFE']->page['description']; + } else { + $og['description'] = $conf['description']; + } + } + $og['description'] = htmlspecialchars($og['description']); - //add tags to html-header - $GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og); + // Get locale + $localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']); + if (isset($localeParts[0])) { + $og['locale'] = str_replace('-', '_', $localeParts[0]); + } - return $content; - } + // Signal to manipulate og-properties before header creation + $this->signalSlotDispatcher->dispatch( + __CLASS__, + 'beforeHeaderCreation', + array(&$og, $this->cObj) + ); - /** - * Renders the header lines to be added from array - * - * @param array $array - * @return string - */ - protected function renderHeaderLines($array) - { - $res = array(); - foreach ($array as $key => $value) - { - if (!empty($value)) - { - // Skip empty values to prevent from empty og property - if (is_array($value)) - { - // A op property with multiple values or child-properties - if (array_key_exists('0', $value)) - { - // A og property that accepts more than one value - foreach ($value as $multiPropertyValue) - { - // Render each value to a new og property meta-tag - if ($key == 'image') - { - // Add image details - $res[] = $this->buildOgImageProperties($key, $multiPropertyValue); - } else - { - $res[] = $this->buildProperty($key, $multiPropertyValue); - } - } - } else - { - // A og property with child-properties - $res .= $this->renderHeaderLines($this->remapArray($key, $value)); - } - } else - { - // A single og property to be rendered - $res[] = $this->buildProperty($key, $value); - } - } - } - return implode(chr(10), ArrayUtility::flatten($res)); - } + //add tags to html-header + $GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og); - /** - * Builds open graph properties for images - * - * @param string $key - * @param mixed $value - * @return array - */ - protected function buildOgImageProperties($key, $value) - { - $res = array(); + return $content; + } - if (is_object($value) && $value instanceOf FileReference) - { - /** @var FileReference $value */ - $res[] = $this->buildProperty($key, - GeneralUtility::locationHeaderUrl($value->getPublicUrl())); - $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); - $res[] = $this->buildProperty($key . ':width', - $value->getProperty('width')); - $res[] = $this->buildProperty($key . ':height', - $value->getProperty('height')); - } else if (is_string($value)) - { - $imageSize = array(); - $parsedUrl = parse_url($value); - if (isset($parsedUrl['host']) && $parsedUrl['host']) - { - // Analyze image with given host - $res[] = $this->buildProperty($key, $value); + /** + * Renders the header lines to be added from array + * + * @param array $array + * @return string + */ + protected function renderHeaderLines($array) + { + $res = array(); + foreach ($array as $key => $value) + { + if (!empty($value)) + { + // Skip empty values to prevent from empty og property + if (is_array($value)) + { + // A op property with multiple values or child-properties + if (array_key_exists('0', $value)) + { + // A og property that accepts more than one value + foreach ($value as $multiPropertyValue) + { + // Render each value to a new og property meta-tag + if ($key == 'image') + { + // Add image details + $res[] = $this->buildOgImageProperties($key, $multiPropertyValue); + } else + { + $res[] = $this->buildProperty($key, $multiPropertyValue); + } + } + } else + { + // A og property with child-properties + $res .= $this->renderHeaderLines($this->remapArray($key, $value)); + } + } else + { + // A single og property to be rendered + $res[] = $this->buildProperty($key, $value); + } + } + } + return implode(chr(10), ArrayUtility::flatten($res)); + } - if (GeneralUtility::getHostname() == $parsedUrl['host']) - { - // Get image absolute filename on own host - $value = GeneralUtility::getFileAbsFileName( - substr($parsedUrl['path'], 1) . - (isset($parsedUrl['query']) && $parsedUrl['query'] ? '?' . $parsedUrl['query'] : '') . - (isset($parsedUrl['fragment']) && $parsedUrl['fragment'] ? '#' . $parsedUrl['fragment'] : '') - ); - } + /** + * Builds open graph properties for images + * + * @param string $key + * @param mixed $value + * @return array + */ + protected function buildOgImageProperties($key, $value) + { + $res = array(); - if (file_exists($value)) - $imageSize = getimagesize($value); - } else - { - // Analyze image with relative filename - $absImagePath = GeneralUtility::getFileAbsFileName($value); - if (file_exists($absImagePath)) - { - $imageSize = getimagesize($absImagePath); + if (is_object($value) && $value instanceOf FileReference) + { + /** @var FileReference $value */ + $res[] = $this->buildProperty($key, + GeneralUtility::locationHeaderUrl($value->getPublicUrl())); + $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); + $res[] = $this->buildProperty($key . ':width', + $value->getProperty('width')); + $res[] = $this->buildProperty($key . ':height', + $value->getProperty('height')); + } else if (is_string($value)) + { + $imageSize = array(); + $parsedUrl = parse_url($value); + if (isset($parsedUrl['host']) && $parsedUrl['host']) + { + // Analyze image with given host + $res[] = $this->buildProperty($key, $value); - $res[] = $this->buildProperty($key, - GeneralUtility::locationHeaderUrl($value)); - } - } + if (GeneralUtility::getHostname() == $parsedUrl['host']) + { + // Get image absolute filename on own host + $value = GeneralUtility::getFileAbsFileName( + substr($parsedUrl['path'], 1) . + (isset($parsedUrl['query']) && $parsedUrl['query'] ? '?' . $parsedUrl['query'] : '') . + (isset($parsedUrl['fragment']) && $parsedUrl['fragment'] ? '#' . $parsedUrl['fragment'] : '') + ); + } - // Add image details if available - if (isset($imageSize['mime']) && $imageSize['mime']) - $res[] = $this->buildProperty($key . ':type', $imageSize['mime']); - if (isset($imageSize[0]) && $imageSize[0]) - $res[] = $this->buildProperty($key . ':width', $imageSize[0]); - if (isset($imageSize[1]) && $imageSize[1]) - $res[] = $this->buildProperty($key . ':height', $imageSize[1]); - } + if (file_exists($value)) + $imageSize = getimagesize($value); + } else + { + // Analyze image with relative filename + $absImagePath = GeneralUtility::getFileAbsFileName($value); + if (file_exists($absImagePath)) + { + $imageSize = getimagesize($absImagePath); - return $res; - } + $res[] = $this->buildProperty($key, + GeneralUtility::locationHeaderUrl($value)); + } + } - /** - * Build meta property tag - * - * @param string $key - * @param string $value - * @return string - */ - protected function buildProperty($key, $value) - { - return ''; - } + // Add image details if available + if (isset($imageSize['mime']) && $imageSize['mime']) + $res[] = $this->buildProperty($key . ':type', $imageSize['mime']); + if (isset($imageSize[0]) && $imageSize[0]) + $res[] = $this->buildProperty($key . ':width', $imageSize[0]); + if (isset($imageSize[1]) && $imageSize[1]) + $res[] = $this->buildProperty($key . ':height', $imageSize[1]); + } - /** - * Remap an array: Add $prefixKey to keys of $array - * - * @param string $prefixKey - * @param array $array - * @return array - */ - protected function remapArray($prefixKey, $array) - { - $res = array(); - foreach ($array as $key => $value) - $res[$prefixKey.':'.$key] = $value; + return $res; + } - return $res; - } + /** + * Build meta property tag + * + * @param string $key + * @param string $value + * @return string + */ + protected function buildProperty($key, $value) + { + return ''; + } + + /** + * Remap an array: Add $prefixKey to keys of $array + * + * @param string $prefixKey + * @param array $array + * @return array + */ + protected function remapArray($prefixKey, $array) + { + $res = array(); + foreach ($array as $key => $value) + $res[$prefixKey.':'.$key] = $value; + + return $res; + } } diff --git a/ext_tables.php b/ext_tables.php index ab031f0..3f3b6b0 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -72,8 +72,9 @@ 'exclude' => 1, 'label' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:pages.tx_jhopengraphprotocol_ogdescription', 'config' => array( - 'type' => 'input', + 'type' => 'text', 'size' => '30', + 'rows' => '3', 'max' => '300', ) ), From 42e934bb82b343d4fb78bf94a7f226f4fdb11adc Mon Sep 17 00:00:00 2001 From: Tobias Pinnekamp Date: Tue, 26 Jul 2016 12:43:19 +0200 Subject: [PATCH 02/13] Revert formatting --- Classes/Service/OgRendererService.php | 536 +++++++++++++------------- 1 file changed, 267 insertions(+), 269 deletions(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 8cd31de..1660dc8 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -2,34 +2,32 @@ namespace Heilmann\JhOpengraphprotocol\Service; /*************************************************************** - * Copyright notice - * - * (c) 2014-2016 Jonathan Heilmann - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ +* Copyright notice +* +* (c) 2014-2016 Jonathan Heilmann +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Extbase\Utility\DebuggerUtility; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -use TYPO3\CMS\Frontend\Page\PageRepository; /** * Class OgRendererService @@ -38,280 +36,280 @@ class OgRendererService implements \TYPO3\CMS\Core\SingletonInterface { - /** - * content Object - * - * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer - */ - public $cObj; + /** + * content Object + * + * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer + */ + public $cObj; - /** - * SignalSlotDispatcher - * - * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher - * @inject - */ - protected $signalSlotDispatcher; + /** + * SignalSlotDispatcher + * + * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher + * @inject + */ + protected $signalSlotDispatcher; - /** - * Main-function to render the Open Graph protocol content. - * - * @param string $content - * @param array $conf - * @return string - */ - public function main($content, $conf) - { - $extKey = 'tx_jhopengraphprotocol'; - $content = ''; - $og = array(); + /** + * Main-function to render the Open Graph protocol content. + * + * @param string $content + * @param array $conf + * @return string + */ + public function main($content, $conf) + { + $extKey = 'tx_jhopengraphprotocol'; + $content = ''; + $og = array(); - if ($this->signalSlotDispatcher == null) { - /* @var \TYPO3\CMS\Extbase\Object\ObjectManager */ - $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); - $this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); - } + if ($this->signalSlotDispatcher == null) { + /* @var \TYPO3\CMS\Extbase\Object\ObjectManager */ + $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); + $this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); + } - // 2013-04-22 kraftb@webconsulting.at - // Check if the tt_news "displaySingle" method has been called before - if (class_exists('tx_jhopengraphttnews_displaySingleHook')) { - $hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook'); - if ($hookObject->singleViewDisplayed()) - return $content; - } - if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) { - $hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class); - if ($hookObject->singleViewDisplayed()) - return $content; - } + // 2013-04-22 kraftb@webconsulting.at + // Check if the tt_news "displaySingle" method has been called before + if (class_exists('tx_jhopengraphttnews_displaySingleHook')) { + $hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook'); + if ($hookObject->singleViewDisplayed()) + return $content; + } + if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) { + $hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class); + if ($hookObject->singleViewDisplayed()) + return $content; + } - //if there has been no return, get og properties and render output + //if there has been no return, get og properties and render output - // Get title - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'])) { - $og['title'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']; - } else { - $og['title'] = $GLOBALS['TSFE']->page['title']; - } - $og['title'] = htmlspecialchars($og['title']); + // Get title + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'])) { + $og['title'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']; + } else { + $og['title'] = $GLOBALS['TSFE']->page['title']; + } + $og['title'] = htmlspecialchars($og['title']); - // Get type - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'])) { - $og['type'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']; - } else { - $og['type'] = $conf['type']; - } - $og['type'] = htmlspecialchars($og['type']); + // Get type + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'])) { + $og['type'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']; + } else { + $og['type'] = $conf['type']; + } + $og['type'] = htmlspecialchars($og['type']); + // Get image $fileRelationPid = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?: $GLOBALS['TSFE']->id; $fileRelationTable = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ? 'pages_language_overlay' : 'pages'; - // Get image /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */ - $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); - $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'tx_jhopengraphprotocol_ogfalimages', $fileRelationPid); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { - // check if an image is given in page --> media, if not use default image - $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'media', $fileRelationPid); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { - $imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']); - if (!empty($imageFileName)) { - $og['image'][] = $imageFileName; - } - } - } + $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); + $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'tx_jhopengraphprotocol_ogfalimages', $fileRelationPid); + if (count($fileObjects)) { + foreach ($fileObjects as $key => $fileObject) { + /** @var FileReference $fileObject */ + $og['image'][] = $fileObject; + } + } else { + // check if an image is given in page --> media, if not use default image + $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'media', $fileRelationPid); + if (count($fileObjects)) { + foreach ($fileObjects as $key => $fileObject) { + /** @var FileReference $fileObject */ + $og['image'][] = $fileObject; + } + } else { + $imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']); + if (!empty($imageFileName)) { + $og['image'][] = $imageFileName; + } + } + } - // Get url - $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); + // Get url + $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); - // Get site_name - if (!empty($conf['sitename'])) { - $og['site_name'] = $conf['sitename']; - } else { - $og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle']; - } - $og['site_name'] = htmlspecialchars($og['site_name']); + // Get site_name + if (!empty($conf['sitename'])) { + $og['site_name'] = $conf['sitename']; + } else { + $og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle']; + } + $og['site_name'] = htmlspecialchars($og['site_name']); - // Get description - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'])) { - $og['description'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription']; - } else { - if (!empty($GLOBALS['TSFE']->page['description'])) { - $og['description'] = $GLOBALS['TSFE']->page['description']; - } else { - $og['description'] = $conf['description']; - } - } - $og['description'] = htmlspecialchars($og['description']); + // Get description + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'])) { + $og['description'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription']; + } else { + if (!empty($GLOBALS['TSFE']->page['description'])) { + $og['description'] = $GLOBALS['TSFE']->page['description']; + } else { + $og['description'] = $conf['description']; + } + } + $og['description'] = htmlspecialchars($og['description']); - // Get locale - $localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']); - if (isset($localeParts[0])) { - $og['locale'] = str_replace('-', '_', $localeParts[0]); - } + // Get locale + $localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']); + if (isset($localeParts[0])) { + $og['locale'] = str_replace('-', '_', $localeParts[0]); + } - // Signal to manipulate og-properties before header creation - $this->signalSlotDispatcher->dispatch( - __CLASS__, - 'beforeHeaderCreation', - array(&$og, $this->cObj) - ); + // Signal to manipulate og-properties before header creation + $this->signalSlotDispatcher->dispatch( + __CLASS__, + 'beforeHeaderCreation', + array(&$og, $this->cObj) + ); - //add tags to html-header - $GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og); + //add tags to html-header + $GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og); - return $content; - } + return $content; + } - /** - * Renders the header lines to be added from array - * - * @param array $array - * @return string - */ - protected function renderHeaderLines($array) - { - $res = array(); - foreach ($array as $key => $value) - { - if (!empty($value)) - { - // Skip empty values to prevent from empty og property - if (is_array($value)) - { - // A op property with multiple values or child-properties - if (array_key_exists('0', $value)) - { - // A og property that accepts more than one value - foreach ($value as $multiPropertyValue) - { - // Render each value to a new og property meta-tag - if ($key == 'image') - { - // Add image details - $res[] = $this->buildOgImageProperties($key, $multiPropertyValue); - } else - { - $res[] = $this->buildProperty($key, $multiPropertyValue); - } - } - } else - { - // A og property with child-properties - $res .= $this->renderHeaderLines($this->remapArray($key, $value)); - } - } else - { - // A single og property to be rendered - $res[] = $this->buildProperty($key, $value); - } - } - } - return implode(chr(10), ArrayUtility::flatten($res)); - } + /** + * Renders the header lines to be added from array + * + * @param array $array + * @return string + */ + protected function renderHeaderLines($array) + { + $res = array(); + foreach ($array as $key => $value) + { + if (!empty($value)) + { + // Skip empty values to prevent from empty og property + if (is_array($value)) + { + // A op property with multiple values or child-properties + if (array_key_exists('0', $value)) + { + // A og property that accepts more than one value + foreach ($value as $multiPropertyValue) + { + // Render each value to a new og property meta-tag + if ($key == 'image') + { + // Add image details + $res[] = $this->buildOgImageProperties($key, $multiPropertyValue); + } else + { + $res[] = $this->buildProperty($key, $multiPropertyValue); + } + } + } else + { + // A og property with child-properties + $res .= $this->renderHeaderLines($this->remapArray($key, $value)); + } + } else + { + // A single og property to be rendered + $res[] = $this->buildProperty($key, $value); + } + } + } + return implode(chr(10), ArrayUtility::flatten($res)); + } - /** - * Builds open graph properties for images - * - * @param string $key - * @param mixed $value - * @return array - */ - protected function buildOgImageProperties($key, $value) - { - $res = array(); + /** + * Builds open graph properties for images + * + * @param string $key + * @param mixed $value + * @return array + */ + protected function buildOgImageProperties($key, $value) + { + $res = array(); - if (is_object($value) && $value instanceOf FileReference) - { - /** @var FileReference $value */ - $res[] = $this->buildProperty($key, - GeneralUtility::locationHeaderUrl($value->getPublicUrl())); - $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); - $res[] = $this->buildProperty($key . ':width', - $value->getProperty('width')); - $res[] = $this->buildProperty($key . ':height', - $value->getProperty('height')); - } else if (is_string($value)) - { - $imageSize = array(); - $parsedUrl = parse_url($value); - if (isset($parsedUrl['host']) && $parsedUrl['host']) - { - // Analyze image with given host - $res[] = $this->buildProperty($key, $value); + if (is_object($value) && $value instanceOf FileReference) + { + /** @var FileReference $value */ + $res[] = $this->buildProperty($key, + GeneralUtility::locationHeaderUrl($value->getPublicUrl())); + $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); + $res[] = $this->buildProperty($key . ':width', + $value->getProperty('width')); + $res[] = $this->buildProperty($key . ':height', + $value->getProperty('height')); + } else if (is_string($value)) + { + $imageSize = array(); + $parsedUrl = parse_url($value); + if (isset($parsedUrl['host']) && $parsedUrl['host']) + { + // Analyze image with given host + $res[] = $this->buildProperty($key, $value); - if (GeneralUtility::getHostname() == $parsedUrl['host']) - { - // Get image absolute filename on own host - $value = GeneralUtility::getFileAbsFileName( - substr($parsedUrl['path'], 1) . - (isset($parsedUrl['query']) && $parsedUrl['query'] ? '?' . $parsedUrl['query'] : '') . - (isset($parsedUrl['fragment']) && $parsedUrl['fragment'] ? '#' . $parsedUrl['fragment'] : '') - ); - } + if (GeneralUtility::getHostname() == $parsedUrl['host']) + { + // Get image absolute filename on own host + $value = GeneralUtility::getFileAbsFileName( + substr($parsedUrl['path'], 1) . + (isset($parsedUrl['query']) && $parsedUrl['query'] ? '?' . $parsedUrl['query'] : '') . + (isset($parsedUrl['fragment']) && $parsedUrl['fragment'] ? '#' . $parsedUrl['fragment'] : '') + ); + } - if (file_exists($value)) - $imageSize = getimagesize($value); - } else - { - // Analyze image with relative filename - $absImagePath = GeneralUtility::getFileAbsFileName($value); - if (file_exists($absImagePath)) - { - $imageSize = getimagesize($absImagePath); + if (file_exists($value)) + $imageSize = getimagesize($value); + } else + { + // Analyze image with relative filename + $absImagePath = GeneralUtility::getFileAbsFileName($value); + if (file_exists($absImagePath)) + { + $imageSize = getimagesize($absImagePath); - $res[] = $this->buildProperty($key, - GeneralUtility::locationHeaderUrl($value)); - } - } + $res[] = $this->buildProperty($key, + GeneralUtility::locationHeaderUrl($value)); + } + } - // Add image details if available - if (isset($imageSize['mime']) && $imageSize['mime']) - $res[] = $this->buildProperty($key . ':type', $imageSize['mime']); - if (isset($imageSize[0]) && $imageSize[0]) - $res[] = $this->buildProperty($key . ':width', $imageSize[0]); - if (isset($imageSize[1]) && $imageSize[1]) - $res[] = $this->buildProperty($key . ':height', $imageSize[1]); - } + // Add image details if available + if (isset($imageSize['mime']) && $imageSize['mime']) + $res[] = $this->buildProperty($key . ':type', $imageSize['mime']); + if (isset($imageSize[0]) && $imageSize[0]) + $res[] = $this->buildProperty($key . ':width', $imageSize[0]); + if (isset($imageSize[1]) && $imageSize[1]) + $res[] = $this->buildProperty($key . ':height', $imageSize[1]); + } - return $res; - } + return $res; + } - /** - * Build meta property tag - * - * @param string $key - * @param string $value - * @return string - */ - protected function buildProperty($key, $value) - { - return ''; - } + /** + * Build meta property tag + * + * @param string $key + * @param string $value + * @return string + */ + protected function buildProperty($key, $value) + { + return ''; + } - /** - * Remap an array: Add $prefixKey to keys of $array - * - * @param string $prefixKey - * @param array $array - * @return array - */ - protected function remapArray($prefixKey, $array) - { - $res = array(); - foreach ($array as $key => $value) - $res[$prefixKey.':'.$key] = $value; + /** + * Remap an array: Add $prefixKey to keys of $array + * + * @param string $prefixKey + * @param array $array + * @return array + */ + protected function remapArray($prefixKey, $array) + { + $res = array(); + foreach ($array as $key => $value) + $res[$prefixKey.':'.$key] = $value; - return $res; - } + return $res; + } } From 2c1417869e8bdf28c8a6affcf4115843010b7273 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Wed, 10 Aug 2016 14:48:27 +0200 Subject: [PATCH 03/13] [TASK] Set version to 1.2.2-dev --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index aa719f6..819a067 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -15,7 +15,7 @@ 'description' => 'Adds the Open Graph protocol properties in meta-tags to the html-header supporting multilingual-websites.', 'category' => 'plugin', 'shy' => 0, - 'version' => '1.2.1', + 'version' => '1.2.2-dev', 'dependencies' => '', 'conflicts' => '', 'priority' => '', From 908c40b958637655e8a28280df1e965b6b96d9ba Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Wed, 10 Aug 2016 14:48:41 +0200 Subject: [PATCH 04/13] [TASK] Update .gitignore --- .gitignore | 56 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d1593b1..ce1e151 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,38 @@ -## TYPO3 v4 -# Ignore serveral upload and file directories. -/fileadmin/user_upload/ -/fileadmin/_temp_/ -/uploads/ -# Ignore cache -/typo3conf/temp_CACHED* -/typo3conf/temp_fieldInfo.php -# Ignore local config which overrides typo3 config. -# You should include your local stuff with `@include('localconf_local.php');` at the end of localconf.php. -# See http://stackoverflow.com/questions/11905360/how-best-to-manage-typo3-installations-using-git for details. -/typo3conf/localconf_local.php -# Ignore system folders, you should have them symlinked. -# If not comment out the following two entries. -/typo3 -/t3lib -# Ignore temp directory. -/typo3temp/ +## +# Local +## +.idea/* + +## +# https://gist.github.com/jonathanheilmann/79228adada3521a90a54 +## + +## +# OSX +## +.DS_Store +.AppleDouble +.LSOverride + +## +# Windows +## +# Windows image file caches +Thumbs.db +ehthumbs.db +# Folder config file +Desktop.ini +# Recycle Bin used on file shares +$RECYCLE.BIN/ +# Windows Installer files +*.cab +*.msi +*.msm +*.msp +# Windows shortcuts +*.lnk + +## +# all OS +## +*.bak \ No newline at end of file From fb288a55cb103f86e0fb2d8076ec1aafc17dee00 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Thu, 11 Aug 2016 13:18:44 +0200 Subject: [PATCH 05/13] [TASK] Code clean up --- Classes/Service/OgRendererService.php | 71 ++++++++++----------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 1660dc8..38eefc8 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -27,7 +27,6 @@ use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\ArrayUtility; -use TYPO3\CMS\Extbase\Utility\DebuggerUtility; /** * Class OgRendererService @@ -64,7 +63,8 @@ public function main($content, $conf) $content = ''; $og = array(); - if ($this->signalSlotDispatcher == null) { + if ($this->signalSlotDispatcher == null) + { /* @var \TYPO3\CMS\Extbase\Object\ObjectManager */ $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); @@ -72,12 +72,14 @@ public function main($content, $conf) // 2013-04-22 kraftb@webconsulting.at // Check if the tt_news "displaySingle" method has been called before - if (class_exists('tx_jhopengraphttnews_displaySingleHook')) { + if (class_exists('tx_jhopengraphttnews_displaySingleHook')) + { $hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook'); if ($hookObject->singleViewDisplayed()) return $content; } - if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) { + if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) + { $hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class); if ($hookObject->singleViewDisplayed()) return $content; @@ -86,20 +88,11 @@ public function main($content, $conf) //if there has been no return, get og properties and render output // Get title - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'])) { - $og['title'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']; - } else { - $og['title'] = $GLOBALS['TSFE']->page['title']; - } - $og['title'] = htmlspecialchars($og['title']); + $og['title'] = htmlspecialchars(!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']) ? + $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'] : + $GLOBALS['TSFE']->page['title']); // Get type - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'])) { - $og['type'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']; - } else { - $og['type'] = $conf['type']; - } - $og['type'] = htmlspecialchars($og['type']); // Get image $fileRelationPid = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?: $GLOBALS['TSFE']->id; @@ -114,6 +107,9 @@ public function main($content, $conf) $og['image'][] = $fileObject; } } else { + $og['type'] = htmlspecialchars(!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']) ? + $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] : + $conf['type']); // check if an image is given in page --> media, if not use default image $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'media', $fileRelationPid); if (count($fileObjects)) { @@ -133,32 +129,28 @@ public function main($content, $conf) $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); // Get site_name - if (!empty($conf['sitename'])) { - $og['site_name'] = $conf['sitename']; - } else { - $og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle']; - } - $og['site_name'] = htmlspecialchars($og['site_name']); + $og['site_name'] = htmlspecialchars(!empty($conf['sitename']) ? + $conf['sitename'] : + $GLOBALS['TSFE']->tmpl->setup['sitetitle']); // Get description - if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'])) { + if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'])) $og['description'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription']; - } else { - if (!empty($GLOBALS['TSFE']->page['description'])) { - $og['description'] = $GLOBALS['TSFE']->page['description']; - } else { - $og['description'] = $conf['description']; - } - } + else + $og['description'] = !empty($GLOBALS['TSFE']->page['description']) ? + $GLOBALS['TSFE']->page['description'] : + $conf['description']; + $og['description'] = htmlspecialchars($og['description']); // Get locale $localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']); - if (isset($localeParts[0])) { + if (isset($localeParts[0])) $og['locale'] = str_replace('-', '_', $localeParts[0]); - } // Signal to manipulate og-properties before header creation + // Please do not use the second parameter ($this->cObj) in your dispatcher, but $GLOBALS['TSFE']->page instead. + // This allows you to use the advantage of easy multilingual page handling. $this->signalSlotDispatcher->dispatch( __CLASS__, 'beforeHeaderCreation', @@ -192,22 +184,13 @@ protected function renderHeaderLines($array) { // A og property that accepts more than one value foreach ($value as $multiPropertyValue) - { // Render each value to a new og property meta-tag - if ($key == 'image') - { - // Add image details - $res[] = $this->buildOgImageProperties($key, $multiPropertyValue); - } else - { - $res[] = $this->buildProperty($key, $multiPropertyValue); - } - } + $res[] = $key == 'image' ? + $this->buildOgImageProperties($key, $multiPropertyValue) : + $this->buildProperty($key, $multiPropertyValue); } else - { // A og property with child-properties $res .= $this->renderHeaderLines($this->remapArray($key, $value)); - } } else { // A single og property to be rendered From 27451b3b190e7f46dc30d9ec019b2842689cc86e Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Thu, 11 Aug 2016 13:23:59 +0200 Subject: [PATCH 06/13] [BUGFIX] Not localized og tag on FE (Related to #23) --- Classes/Service/OgRendererService.php | 65 +++++++++++++++--------- Resources/Private/Language/locallang.xml | 2 + ext_conf_template.txt | 11 ++++ ext_tables.php | 29 +++++++++-- 4 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 ext_conf_template.txt diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 38eefc8..1870613 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -25,6 +25,7 @@ ***************************************************************/ use TYPO3\CMS\Core\Resource\FileReference; +use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\ArrayUtility; @@ -93,37 +94,51 @@ public function main($content, $conf) $GLOBALS['TSFE']->page['title']); // Get type - - // Get image - $fileRelationPid = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?: $GLOBALS['TSFE']->id; - $fileRelationTable = $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ? 'pages_language_overlay' : 'pages'; - - /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */ - $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); - $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'tx_jhopengraphprotocol_ogfalimages', $fileRelationPid); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { $og['type'] = htmlspecialchars(!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']) ? $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] : $conf['type']); + + // Get images + /** @var FileRepository $fileRepository */ + $fileRepository = GeneralUtility::makeInstance(FileRepository::class); + + $fileObjects = array(); + if ($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID']) + { + // Get images if there is a language overlay + // This is somehow a hack, as l10n_mode 'mergeIfNotBlack' does not work in this case. + // PageRepository->shouldFieldBeOverlaid does not work for config type 'inline' with "DEFAULT '0'" database config, + // as an empty inline field is '0', and '0' is treated as not empty. + // Setting 'Default NULL' in database config won't work, too, as it isn't easier to check, if value in + // $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] is related to table 'pages' or 'pages_language_overlay'. + + // Parameter 3 (uid) is always the pages' uid, as sys_file_reference always references to the pages' uid, even on pages_language_overlay + $overlayFileObjects = $fileRepository->findByRelation('pages_language_overlay', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id); + if (count($overlayFileObjects) > 0) + $fileObjects = $overlayFileObjects; + else if (isset($GLOBALS['TCA']['pages_language_overlay']['columns']['tx_jhopengraphprotocol_ogfalimages']['l10n_mode']) && + $GLOBALS['TCA']['pages_language_overlay']['columns']['tx_jhopengraphprotocol_ogfalimages']['l10n_mode'] === 'mergeIfNotBlank') + $fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id); + } else + $fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id); + + if (count($fileObjects) === 0) + { // check if an image is given in page --> media, if not use default image - $fileObjects = $fileRepository->findByRelation($fileRelationTable, 'media', $fileRelationPid); - if (count($fileObjects)) { - foreach ($fileObjects as $key => $fileObject) { - /** @var FileReference $fileObject */ - $og['image'][] = $fileObject; - } - } else { + $fileObjects = $fileRepository->findByRelation( + ($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ? 'pages_language_overlay' : 'pages'), + 'media', + ($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?:$GLOBALS['TSFE']->id) + ); + if (count($fileObjects) === 0) + { $imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']); - if (!empty($imageFileName)) { + if (!empty($imageFileName)) $og['image'][] = $imageFileName; - } - } - } + } else + $og['image'] = $fileObjects; + } else + $og['image'] = $fileObjects; // Get url $og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); diff --git a/Resources/Private/Language/locallang.xml b/Resources/Private/Language/locallang.xml index 115e8af..f26aa49 100644 --- a/Resources/Private/Language/locallang.xml +++ b/Resources/Private/Language/locallang.xml @@ -11,6 +11,7 @@ + @@ -19,6 +20,7 @@ + diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..fe45f1a --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,11 @@ +# cat=basic/enable/100; type=boolean; label=Title mergeIfNotBlank: Use title of default language if localized title is empty +languageOverlay.tx_jhopengraphprotocol_ogtitle.mergeIfNotBlank = 0 + +# cat=basic/enable/101; type=boolean; label=Type mergeIfNotBlank: Use type of default language if localized type is empty +languageOverlay.tx_jhopengraphprotocol_ogtype.mergeIfNotBlank = 0 + +# cat=basic/enable/102; type=boolean; label=Image(s) mergeIfNotBlank: Use image(s) of default language if localized image(s) is empty +languageOverlay.tx_jhopengraphprotocol_ogfalimages.mergeIfNotBlank = 0 + +# cat=basic/enable/103; type=boolean; label=Description mergeIfNotBlank: Use description of default language if localized description is empty +languageOverlay.tx_jhopengraphprotocol_ogdescription.mergeIfNotBlank = 0 \ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index 3f3b6b0..5d55692 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -1,7 +1,9 @@ array( + 'showPossibleLocalizationRecords' => true, + 'showRemovedLocalizationRecords' => true, + 'showSynchronizationLink' => true, + 'showAllLocalizationLink' => true, + 'enableControls' => array( 'sort' => true, ), ), + 'behaviour' => array( + 'localizationMode' => 'keep', + 'localizeChildrenAtParentLocalization' => TRUE, + ), 'foreign_types' => array( '0' => array( 'showitem' => ' @@ -66,7 +77,7 @@ ), ), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] - ), + ) ), 'tx_jhopengraphprotocol_ogdescription' => array( 'exclude' => 1, @@ -84,6 +95,18 @@ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $tempColumns, 1); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages', '--div--;LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:pages.tab_title,tx_jhopengraphprotocol_ogtitle;;;;1-1-1, tx_jhopengraphprotocol_ogtype, tx_jhopengraphprotocol_ogfalimages, tx_jhopengraphprotocol_ogdescription'); +foreach ($tempColumns as $tempColumnKey => $tempColumnValue) +{ + $tempColumns[$tempColumnKey]['l10n_cat'] = 'text'; + // Set l10n_mode for pages_language_overlay + if (isset($extConf['languageOverlay'][$tempColumnKey]['mergeIfNotBlank']) && $extConf['languageOverlay'][$tempColumnKey]['mergeIfNotBlank']) + $tempColumns[$tempColumnKey]['l10n_mode'] = 'mergeIfNotBlank'; + + // Change label for tx_jhopengraphprotocol_ogfalimages if l10n_mode is 'mergeIfNotBlank' to add mode information + if ($tempColumnKey === 'tx_jhopengraphprotocol_ogfalimages' && $tempColumns[$tempColumnKey]['l10n_mode'] === 'mergeIfNotBlank') + $tempColumns[$tempColumnKey]['label'] = 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:pages.tx_jhopengraphprotocol_ogimage.mergeIfNotBlank'; +} + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages_language_overlay', $tempColumns, 1); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages_language_overlay', '--div--;LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:pages.tab_title,tx_jhopengraphprotocol_ogtitle;;;;1-1-1, tx_jhopengraphprotocol_ogtype, tx_jhopengraphprotocol_ogfalimages, tx_jhopengraphprotocol_ogdescription'); From 80775cb6ffd6af601b964245dd3f812aa2bdc89e Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Fri, 12 Aug 2016 19:57:50 +0200 Subject: [PATCH 07/13] [BUGFIX] Not localized og tag on FE (Related to #23) --- Classes/Service/OgRendererService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 1870613..fe0edbb 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -113,7 +113,7 @@ public function main($content, $conf) // $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] is related to table 'pages' or 'pages_language_overlay'. // Parameter 3 (uid) is always the pages' uid, as sys_file_reference always references to the pages' uid, even on pages_language_overlay - $overlayFileObjects = $fileRepository->findByRelation('pages_language_overlay', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id); + $overlayFileObjects = $fileRepository->findByRelation('pages_language_overlay', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID']); if (count($overlayFileObjects) > 0) $fileObjects = $overlayFileObjects; else if (isset($GLOBALS['TCA']['pages_language_overlay']['columns']['tx_jhopengraphprotocol_ogfalimages']['l10n_mode']) && From 7cde56c90277aeecc166ce025f5d57d8943b3124 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Sat, 13 Aug 2016 16:46:43 +0200 Subject: [PATCH 08/13] [BUGFIX] Not localized og tag on FE (Related to #23) --- ext_tables.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext_tables.php b/ext_tables.php index 5d55692..ac8c00b 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -55,7 +55,7 @@ ), ), 'behaviour' => array( - 'localizationMode' => 'keep', + 'localizationMode' => 'select', 'localizeChildrenAtParentLocalization' => TRUE, ), 'foreign_types' => array( @@ -102,6 +102,10 @@ if (isset($extConf['languageOverlay'][$tempColumnKey]['mergeIfNotBlank']) && $extConf['languageOverlay'][$tempColumnKey]['mergeIfNotBlank']) $tempColumns[$tempColumnKey]['l10n_mode'] = 'mergeIfNotBlank'; + // Don't display language diff, it's really ugly + if ($tempColumnKey === 'tx_jhopengraphprotocol_ogfalimages') + $tempColumns[$tempColumnKey]['l10n_display'] = 'hideDiff'; + // Change label for tx_jhopengraphprotocol_ogfalimages if l10n_mode is 'mergeIfNotBlank' to add mode information if ($tempColumnKey === 'tx_jhopengraphprotocol_ogfalimages' && $tempColumns[$tempColumnKey]['l10n_mode'] === 'mergeIfNotBlank') $tempColumns[$tempColumnKey]['label'] = 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:pages.tx_jhopengraphprotocol_ogimage.mergeIfNotBlank'; From 3c74af9d1ae027e0ecfcf98d08b5a45d8483d189 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Wed, 17 Aug 2016 17:33:37 +0200 Subject: [PATCH 09/13] [BUGFIX] Not localized og tag on FE (Related to #23) Removed deprecated comment --- Classes/Service/OgRendererService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index fe0edbb..57e0538 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -112,7 +112,6 @@ public function main($content, $conf) // Setting 'Default NULL' in database config won't work, too, as it isn't easier to check, if value in // $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] is related to table 'pages' or 'pages_language_overlay'. - // Parameter 3 (uid) is always the pages' uid, as sys_file_reference always references to the pages' uid, even on pages_language_overlay $overlayFileObjects = $fileRepository->findByRelation('pages_language_overlay', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID']); if (count($overlayFileObjects) > 0) $fileObjects = $overlayFileObjects; From cdb635270d137fa79c88c7ecf02bd98f017f93f9 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Wed, 17 Aug 2016 17:37:02 +0200 Subject: [PATCH 10/13] [BETA-RELEASE] Release of beta version 1.2.2-beta --- composer.json | 2 +- ext_emconf.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9dc75d1..c0e87c7 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "support": { "issues": "https://github.com/jonathanheilmann/ext-jh_opengraphprotocol/issues" }, - "version": "1.2.1", + "version": "1.2.2-beta", "require": { "typo3/cms": "~6.2,~7.6" }, diff --git a/ext_emconf.php b/ext_emconf.php index 819a067..72059b2 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -15,7 +15,7 @@ 'description' => 'Adds the Open Graph protocol properties in meta-tags to the html-header supporting multilingual-websites.', 'category' => 'plugin', 'shy' => 0, - 'version' => '1.2.2-dev', + 'version' => '1.2.2-beta', 'dependencies' => '', 'conflicts' => '', 'priority' => '', From 0c761edc543c30653e10626bd19b8183d8b11600 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Wed, 17 Aug 2016 18:51:07 +0200 Subject: [PATCH 11/13] [BUGFIX] Image width and height is 0 (Fixes #41) Calculating metaData is part of FAL and not part of an extension. The extension should check if the value is valid and render if it is. --- Classes/Service/OgRendererService.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Service/OgRendererService.php b/Classes/Service/OgRendererService.php index 57e0538..270a1e1 100644 --- a/Classes/Service/OgRendererService.php +++ b/Classes/Service/OgRendererService.php @@ -229,13 +229,13 @@ protected function buildOgImageProperties($key, $value) if (is_object($value) && $value instanceOf FileReference) { /** @var FileReference $value */ - $res[] = $this->buildProperty($key, - GeneralUtility::locationHeaderUrl($value->getPublicUrl())); - $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); - $res[] = $this->buildProperty($key . ':width', - $value->getProperty('width')); - $res[] = $this->buildProperty($key . ':height', - $value->getProperty('height')); + $res[] = $this->buildProperty($key, GeneralUtility::locationHeaderUrl($value->getPublicUrl())); + if ($value->getMimeType()) + $res[] = $this->buildProperty($key . ':type', $value->getMimeType()); + if ($value->getProperty('width')) + $res[] = $this->buildProperty($key . ':width', $value->getProperty('width')); + if ($value->getProperty('height')) + $res[] = $this->buildProperty($key . ':height', $value->getProperty('height')); } else if (is_string($value)) { $imageSize = array(); From 68445db737629f7ee4b509bc5e6be0d823e2e86f Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Sat, 10 Sep 2016 10:45:44 +0200 Subject: [PATCH 12/13] [TASK] Update documentation (Related to #23) --- Documentation/Administrator/Index.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/Administrator/Index.rst b/Documentation/Administrator/Index.rst index ad4c6d6..c68b964 100644 --- a/Documentation/Administrator/Index.rst +++ b/Documentation/Administrator/Index.rst @@ -18,6 +18,8 @@ Installation - import and install the extension +- configure extension in Extension Manager + - include static template “Open Graph protocol” - use the Constant-Editor to edit the global Open Graph properties @@ -25,6 +27,17 @@ Installation - use the page-settings for setting the local Open Graph properties +.. _admin-extConfiguration: + +Extension configuration +----------------------- + +Since version 1.2.2 you are able to control the localization mode of each field. + +By default localized pages do not inherit fields from default language if they are empty/blank. +If you want to enable this behavior, configure extension jh_opengraphprotocol and set +">FieldToInheritFromDefaultLanguage< mergeIfNotBlank". + .. _admin-updating: From 65dc2688306aba3299109f01907461192a5d8797 Mon Sep 17 00:00:00 2001 From: jonathanheilmann Date: Sat, 10 Sep 2016 10:49:47 +0200 Subject: [PATCH 13/13] [RELEASE] Release of version 1.2.2 --- Documentation/ChangeLog/Index.rst | 8 ++++++++ Documentation/Settings.yml | 2 +- composer.json | 2 +- ext_emconf.php | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/ChangeLog/Index.rst b/Documentation/ChangeLog/Index.rst index 05a117f..a145fb6 100644 --- a/Documentation/ChangeLog/Index.rst +++ b/Documentation/ChangeLog/Index.rst @@ -22,6 +22,14 @@ ChangeLog :Changes: Changes + - :Version: + 1.2.2 + + :Changes: + \* [TASK] Change description field to textarea + + \* [BUGFIX] #37 Not localized og tag on FE + - :Version: 1.2.1 diff --git a/Documentation/Settings.yml b/Documentation/Settings.yml index 8abaed3..ae4d136 100644 --- a/Documentation/Settings.yml +++ b/Documentation/Settings.yml @@ -11,7 +11,7 @@ conf.py: copyright: 2012-2016 project: Open Graph protocol version: 1.2 - release: 1.2.1 + release: 1.2.2 intersphinx_mapping: t3tsref: - http://docs.typo3.org/typo3cms/TyposcriptReference/ diff --git a/composer.json b/composer.json index c0e87c7..9f67e2a 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "support": { "issues": "https://github.com/jonathanheilmann/ext-jh_opengraphprotocol/issues" }, - "version": "1.2.2-beta", + "version": "1.2.2", "require": { "typo3/cms": "~6.2,~7.6" }, diff --git a/ext_emconf.php b/ext_emconf.php index 72059b2..fa1898d 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -15,7 +15,7 @@ 'description' => 'Adds the Open Graph protocol properties in meta-tags to the html-header supporting multilingual-websites.', 'category' => 'plugin', 'shy' => 0, - 'version' => '1.2.2-beta', + 'version' => '1.2.2', 'dependencies' => '', 'conflicts' => '', 'priority' => '',