Created
July 11, 2017 08:54
-
-
Save einpraegsam/b8b2ebc7a9473f74033b8e81d0cdb310 to your computer and use it in GitHub Desktop.
Revisions
-
einpraegsam created this gist
Jul 11, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <?php namespace In2code\Extkey\Hooks; /** * Class RealurlDecoding */ class RealurlDecoding { /** * @param array $parameter * @return void */ public function convert(array &$parameter) { if ($this->isDetailLink($parameter)) { $newUrl = $this->getSpeakingUrlFromWebShortage($parameter['URL']); if ($newUrl !== '') { $parameter['URL'] = $newUrl; } } } /** * Check if uri is just something like "lastname.firstname" * * @param array $parameter * @return bool */ protected function isDetailLink(array $parameter): bool { return preg_replace('~([a-z\-]+\.[a-z\-]+)~', '', $parameter['URL']) === ''; } /** * Get speaking url from database from webshortage + prepending "/" * @param string $webShortage * @return string */ protected function getSpeakingUrlFromWebShortage(string $webShortage): string { $row = (array)$GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( 'speaking_url', 'tx_realurl_urldata', 'speaking_url like "%' . $webShortage . '%" and (expire = 0 or expire > ' . time() . ')' ); if (!empty($row['speaking_url'])) { return '/' . $row['speaking_url']; } return ''; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <?php namespace In2code\Extkey\Hooks; use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Class RealurlEncoding */ class RealurlEncoding { /** * @param array $parameter * @return void */ public function convert(array &$parameter) { if ($this->isDetailLink($parameter)) { $parameter['URL'] = $this->getWebShortageFromUri($parameter['URL']); } } /** * Check if there is the need of building a link with &tx_extkey_pi1[action]=detail * * @param array $parameter * @return bool */ protected function isDetailLink(array $parameter): bool { return !empty($parameter['params']['args']['addParams']) && stristr($parameter['params']['args']['addParams'], '&tx_extkey_pi1[action]=detail'); } /** * Get last folder from path * "/folder1/folder2/lastname.firstname/" => "lastname.firstname" * * @param string $uri * @return string */ protected function getWebShortageFromUri(string $uri): string { $parts = GeneralUtility::trimExplode('/', $uri, true); return end($parts); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <?php if (!defined('TYPO3_MODE')) { die('Access denied.'); } call_user_func(function () { $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['encodeSpURL_postProc'][] = 'EXT:extkey/Classes/Hooks/RealurlEncoding.php:In2code\Extkey\Hooks\RealurlEncoding->convert'; $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['decodeSpURL_preProc'][] = 'EXT:extkey/Classes/Hooks/RealurlDecoding.php:In2code\Extkey\Hooks\RealurlDecoding->convert'; });