/** * Will store a record in a cachetable holding the value of the "cHash" parameter in a link, if any. * Background: * The "cHash" parameter is a hash over the values in the Query String of a URL and it "authenticates" the URL to the frontend so we can safely cache page content with that parameter combination. * Technically, there is no problem with the "cHash" parameter - it is like any other parameter something we could encode with Speaking URLs. The problem is: a cHash string is not "speaking" (and never will be!) * So; the only option we are left with if we want to remove the "?cHash=...:" remains in URLs and at the same time do not want to include it in the virtual path is; store it in the database! * This is what this function does: Stores a record in the database which relates the cHash value to a hash id of the URL. This is done ONLY if the "cHash" parameter is the only one left which would make the URL non-speaking. Otherwise it is left behind. * Obviously, this whole thing only works if there is a function in the decode part which will look up the cHash again and include it in the GET parameters resolved from the Speaking URL - but there is of course... * * @param string $newUrl URL path (being hashed to an integer and cHash value related to this.) * @param array $paramKeyValues Params $array array, passed by reference. If "cHash" is the only value left it will be put in the cache table and the value is unset in the array. * @return void * @see decodeSpURL_cHashCache() */ protected function encodeSpURL_cHashProcessing($newUrl, &$paramKeyValues) { // If "cHash" is the ONLY parameter left... // (if there are others our problem is that the cHash probably covers those // as well and if we include the cHash anyways we might get duplicates for // the same speaking URL in the cache table!) if (isset($paramKeyValues['cHash'])) { if ($this->rebuildCHash) { $cHashParameters = array_merge($this->cHashParameters, $paramKeyValues); unset($cHashParameters['cHash']); $cHashParameters = $this->apiWrapper->getRelevantChashParameters($this->apiWrapper->implodeArrayForUrl('', $cHashParameters)); unset($cHashParameters['']); if (count($cHashParameters) == 1) { // No cHash needed. unset($paramKeyValues['cHash']); } elseif (count($cHashParameters) > 1) { $paramKeyValues['cHash'] = $this->apiWrapper->calculateChash($cHashParameters); } unset($cHashParameters); } if ($this->extConf['init']['enableCHashCache'] && count($paramKeyValues) == 1) { $stringForHash = $newUrl; if (count($this->additionalParametersForChash)) { $stringForHash .= '|' . serialize($this->additionalParametersForChash); } $spUrlHash = md5($stringForHash); /** @noinspection PhpUndefinedMethodInspection */ $spUrlHashQuoted = $GLOBALS['TYPO3_DB']->fullQuoteStr($spUrlHash, 'tx_realurl_chashcache'); // first, look if a cHash is already there for this SpURL /** @noinspection PhpUndefinedMethodInspection */ list($row) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('chash_string', 'tx_realurl_chashcache', 'spurl_hash=' . $spUrlHashQuoted); if (!is_array($row)) { // Nothing found, insert to the cache $data = array('spurl_hash' => $spUrlHash, 'spurl_string' => $this->enableChashUrlDebug ? $stringForHash : null, 'chash_string' => $paramKeyValues['cHash']); /** @noinspection PhpUndefinedMethodInspection */ $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_realurl_chashcache', $data); } else { // If one found, check if it is different, and if so update if ($row['chash_string'] != $paramKeyValues['cHash']) { // If that chash_string is different from the one we want to // insert, that might be a bug or mean that encryptionKey was // changed so cHash values will be different now // In any case we will just silently update the value $data = array('chash_string' => $paramKeyValues['cHash']); /** @noinspection PhpUndefinedMethodInspection */ $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_chashcache', 'spurl_hash=' . $spUrlHashQuoted, $data); } } // Unset "cHash" (and array should now be empty!) unset($paramKeyValues['cHash']); } } }