diff --git a/Classes/Backend/PageLayoutHeader.php b/Classes/Backend/PageLayoutHeader.php index d5dba9fb..5235a672 100644 --- a/Classes/Backend/PageLayoutHeader.php +++ b/Classes/Backend/PageLayoutHeader.php @@ -3,7 +3,6 @@ use TYPO3\CMS\Backend\Controller\PageLayoutController; use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; @@ -30,8 +29,6 @@ class PageLayoutHeader 'languageKeyToLocaleMapping' => [] ], 'menuActions' => [], - 'previewDomain' => null, - 'previewUrlTemplate' => '', 'viewSettings' => [] ]; @@ -76,12 +73,8 @@ public function render() { $moduleData = BackendUtility::getModuleData(['language'], [], 'web_layout'); $pageId = (int)GeneralUtility::_GET('id'); - - if (!$this->showSnippetPreview()) { - return ''; - } - $currentPage = $this->getCurrentPage($pageId, $moduleData); + if (!YoastUtility::snippetPreviewEnabled($pageId, $currentPage)) { return ''; } @@ -136,24 +129,6 @@ public function render() return ''; } - /** - * Check to see if snippet preview has to be shown - * - * @return bool - */ - protected function showSnippetPreview(): bool - { - if (!$GLOBALS['BE_USER'] instanceof BackendUserAuthentication || - !$GLOBALS['BE_USER']->check('non_exclude_fields', 'pages:tx_yoastseo_snippetpreview')) { - return false; - } - - if ((bool)$GLOBALS['BE_USER']->uc['hideYoastInPageModule']) { - return false; - } - return true; - } - /** * @param $pageId * @param $moduleData diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index e5b84df1..af42d8e4 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -50,8 +50,6 @@ class ModuleController extends ActionController 'languageKeyToLocaleMapping' => [] ], 'menuActions' => [], - 'previewDomain' => null, - 'previewUrlTemplate' => '', 'viewSettings' => [] ]; diff --git a/Classes/Service/PreviewService.php b/Classes/Service/PreviewService.php index 33d0c3de..a66b97d5 100644 --- a/Classes/Service/PreviewService.php +++ b/Classes/Service/PreviewService.php @@ -65,7 +65,8 @@ public function getPreviewData($uriToCheck, $pageId) */ protected function getContentFromUrl($uriToCheck): string { - $GLOBALS['TYPO3_CONF_VARS']['HTTP']['verify'] = false; + $backupSettings = $GLOBALS['TYPO3_CONF_VARS']['HTTP']; + $this->setHttpOptions(); $report = []; $content = GeneralUtility::getUrl( $uriToCheck, @@ -78,6 +79,7 @@ protected function getContentFromUrl($uriToCheck): string $report ); + $GLOBALS['TYPO3_CONF_VARS']['HTTP'] = $backupSettings; if ((int)$report['error'] === 0) { return $content; } @@ -192,4 +194,27 @@ protected function stripTagsContent($text, $tags = '', $invert = false) return $text; } + + /** + * Set http options for the preview request + */ + protected function setHttpOptions() + { + $GLOBALS['TYPO3_CONF_VARS']['HTTP']['verify'] = false; + if (!isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['previewSettings']['basicAuth'])) { + return; + } + + $basicAuth = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['previewSettings']['basicAuth']; + if (!is_array($basicAuth) || !isset($basicAuth['username'], $basicAuth['password'])) { + return; + } + + if (!empty($basicAuth['username']) && !empty($basicAuth['password'])) { + $GLOBALS['TYPO3_CONF_VARS']['HTTP']['auth'] = [ + $basicAuth['username'], + $basicAuth['password'] + ]; + } + } } diff --git a/Classes/Utility/YoastUtility.php b/Classes/Utility/YoastUtility.php index dbeaafc3..57efee7e 100644 --- a/Classes/Utility/YoastUtility.php +++ b/Classes/Utility/YoastUtility.php @@ -14,8 +14,16 @@ * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS; +use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Package\Exception; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; +use TYPO3\CMS\Extbase\Object\ObjectManager; /** * Class YoastUtility @@ -69,10 +77,17 @@ public static function getAllowedDoktypes($configuration = null, $returnInString */ public static function snippetPreviewEnabled($pageId, array $pageRecord, $pageTs = null) { - $showPreview = !$pageRecord['tx_yoastseo_hide_snippet_preview']; + if (!$GLOBALS['BE_USER'] instanceof BackendUserAuthentication || + !$GLOBALS['BE_USER']->check('non_exclude_fields', 'pages:tx_yoastseo_snippetpreview')) { + return false; + } + + if ((bool)$GLOBALS['BE_USER']->uc['hideYoastInPageModule']) { + return false; + } if ($pageTs === null) { - $pageTs = CMS\Backend\Utility\BackendUtility::getPagesTSconfig($pageId); + $pageTs = BackendUtility::getPagesTSconfig($pageId); } if (is_array($pageTs) && @@ -83,10 +98,10 @@ public static function snippetPreviewEnabled($pageId, array $pageRecord, $pageTs array_key_exists('disableSnippetPreview', $pageTs['mod.']['web_SeoPlugin.']) && (int)$pageTs['mod.']['web_SeoPlugin.']['disableSnippetPreview'] === 1 ) { - $showPreview = false; + return false; } - return $showPreview; + return ($pageRecord['tx_yoastseo_hide_snippet_preview']) ? false : true; } /** @@ -102,7 +117,7 @@ public static function getFocusKeywordOfPage($uid, $table = 'pages') return ''; } - $record = CMS\Backend\Utility\BackendUtility::getRecord($table, $uid); + $record = BackendUtility::getRecord($table, $uid); if (\is_array($record) && array_key_exists(self::COLUMN_NAME_FOCUSKEYWORD, $record)) { $focusKeyword = $record[self::COLUMN_NAME_FOCUSKEYWORD]; } @@ -117,7 +132,7 @@ public static function getFocusKeywordOfPage($uid, $table = 'pages') foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['get_focus_keyword'] as $_funcRef) { if ($_funcRef) { $tmp = new \stdClass(); - CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $params, $tmp); + GeneralUtility::callUserFunction($_funcRef, $params, $tmp); } } } @@ -133,7 +148,7 @@ public static function getFocusKeywordOfPage($uid, $table = 'pages') public static function getRelatedKeyphrases($parentTable, $parentId): array { $config = []; - $queryBuilder = CMS\Core\Utility\GeneralUtility::makeInstance(CMS\Core\Database\ConnectionPool::class)->getQueryBuilderForTable('tx_yoast_seo_premium_focus_keywords'); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_yoast_seo_premium_focus_keywords'); if ($queryBuilder) { $relatedKeyphrases = $queryBuilder->select('*') ->from('tx_yoast_seo_premium_focus_keywords') @@ -160,7 +175,7 @@ public static function getRelatedKeyphrases($parentTable, $parentId): array */ public static function isPremiumInstalled() { - return (bool)CMS\Core\Utility\ExtensionManagementUtility::isLoaded('yoast_seo_premium'); + return (bool)ExtensionManagementUtility::isLoaded('yoast_seo_premium'); } /** @@ -187,23 +202,21 @@ public static function inProductionMode($configuration = null) protected static function getTypoScriptConfiguration() { - /** @var CMS\Extbase\Object\ObjectManager $objectManager */ - $objectManager = CMS\Core\Utility\GeneralUtility::makeInstance(CMS\Extbase\Object\ObjectManager::class); - /** @var CMS\Extbase\Configuration\ConfigurationManager $configurationManager */ - $configurationManager = $objectManager->get(CMS\Extbase\Configuration\ConfigurationManager::class); - $configuration = $configurationManager->getConfiguration( - CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, + /** @var ObjectManager $objectManager */ + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + /** @var ConfigurationManager $configurationManager */ + $configurationManager = $objectManager->get(ConfigurationManager::class); + return $configurationManager->getConfiguration( + ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'yoastseo' ); - - return $configuration; } /** * @param string $utm_term * @param string $utm_content * @param string $utm_source * @return string - * @throws CMS\Core\Package\Exception + * @throws Exception */ public static function getYoastLink($utm_term = 'Go premium', $utm_content = '', $utm_source = 'yoast-seo-for-typo3') { @@ -216,9 +229,9 @@ public static function getYoastLink($utm_term = 'Go premium', $utm_content = '', 'utm_campaign' => 'typo3-ad', 'php_version' => $php_version[1] ?: 'unknown', 'platform' => 'TYPO3', - 'platform_version' => CMS\Core\Utility\VersionNumberUtility::getNumericTypo3Version(), + 'platform_version' => VersionNumberUtility::getNumericTypo3Version(), 'software' => self::isPremiumInstalled() ? 'premium' : 'free', - 'software_version' => CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('yoast_seo'), + 'software_version' => ExtensionManagementUtility::getExtensionVersion('yoast_seo'), 'role' => '' ]; diff --git a/Documentation/Configuration/SnippetPreview/Index.rst b/Documentation/Configuration/SnippetPreview/Index.rst index bbcdf565..e88a9042 100644 --- a/Documentation/Configuration/SnippetPreview/Index.rst +++ b/Documentation/Configuration/SnippetPreview/Index.rst @@ -37,3 +37,14 @@ also disable the snippet preview based on PageTs. Below an example to hide page disableSnippetPreview = 1 } [global] + +Basic auth configuration +------------------------ +For environments which are protected by Basic auth, it's possible to set username and password through :php:`$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['previewSettings']['basicAuth']` + +.. code-block:: php + + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['yoast_seo']['previewSettings']['basicAuth'] = [ + 'username' => 'authUsername', + 'password' => 'authPassword' + ]; \ No newline at end of file diff --git a/ext_localconf.php b/ext_localconf.php index 73bd1409..7210b972 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -155,7 +155,12 @@ 'showSocialTab' => true, 'showAdvancedTab' => true ], - 'previewUrlTemplate' => '/?id=%d&type=%d&L=%d', + 'previewSettings' => [ + 'basicAuth' => [ + 'username' => '', + 'password' => '', + ] + ], 'overview_filters' => [ '10' => [ 'key' => 'cornerstone',