Index: typo3/sysext/indexed_search/class.indexer.php =================================================================== --- typo3/sysext/indexed_search/class.indexer.php (revision 7131) +++ typo3/sysext/indexed_search/class.indexer.php (working copy) @@ -784,8 +782,8 @@ $qParts = parse_url($linkSource); // parse again due to new linkSource! } - if ($qParts['scheme']) { - if ($this->indexerConfig['indexExternalURLs']) { + if (!$linkInfo['localPath'] && $qParts['scheme']) { + if ($this->indexerConfig['indexExternalURLs']) { // Index external URL (http or otherwise) $this->indexExternalUrl($linkSource); } @@ -854,18 +852,11 @@ switch (strtolower($firstTagName)) { case 'a': - $src = $params[0]['href']; - if ($src) { - // Check if a local path to that file has been set - useful if you are using a download script. - $md5 = t3lib_div::shortMD5($src); - if (is_array($indexLocalFiles=$GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'])) { - $localPath = isset($indexLocalFiles[$md5]) ? $indexLocalFiles[$md5] : ''; - } else $localPath=false; - + if ($params[0]['href'] && $params[0]['href']{0} != '#') { $list[] = array( 'tag' => $v, 'href' => $params[0]['href'], - 'localPath' => $localPath + 'localPath' => $this->createLocalPath($params[0]['href']) ); } break; @@ -876,16 +867,107 @@ return $list; } + /** + * Checks if the file is local + * + * @param $sourcePath + */ + protected function createLocalPath($sourcePath) { + static $pathFunctions = array( + 'createLocalPathFromT3vars', + 'createLocalPathUsingAbsRefPrefix', + 'createLocalPathUsingDomainURL', + 'createLocalPathFromAbsoluteURL' + ); + foreach ($pathFunctions as $functionName) { + $localPath = $this->$functionName($sourcePath); + if ($localPath != '') { + break; + } + } + return $localPath; + } + /** + * Attempts to create a local file path from T3VARs. This is useful for + * various download extensions that hide actual file name but still want the + * file to be indexed. + * + * @param string $sourcePath + * @return string + */ + protected function createLocalPathFromT3vars($sourcePath) { + $localPath = ''; + $indexLocalFiles = $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles']; + if (is_array($indexLocalFiles)) { + $md5 = t3lib_div::shortMD5($sourcePath); + if (isset($indexLocalFiles[$md5]) && is_file($indexLocalFiles[$md5])) { + $localPath = $indexLocalFiles[$md5]; + } + } + return $localPath; + } + /** + * Attempts to create a local file path by matching a current request URL. + * + * @param string $sourcePath + * @return string + */ + protected function createLocalPathUsingDomainURL($sourcePath) { + $baseURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); + $baseURLLength = strlen($baseURL); + if (substr($sourcePath, 0, $baseURLLength) == $baseURL) { + $sourcePath = substr($sourcePath, $baseURLLength); + $localPath = PATH_site . $sourcePath; + if (!is_file($localPath)) { + $localPath = ''; + } + } + return $localPath; + } + /** + * Attempts to create a local file path by matching absRefPrefix. This + * requires TSFE. If TSFE is missing, this function does nothing. + * + * @param string $sourcePath + * @return string + */ + protected function createLocalPathUsingAbsRefPrefix($sourcePath) { + $localPath = ''; + if ($GLOBALS['TSFE'] instanceof tslib_fe) { + $absRefPrefix = $GLOBALS['TSFE']->config['config']['absRefPrefix']; + $absRefPrefixLength = strlen($absRefPrefix); + if (substr($sourcePath, 0, $absRefPrefixLength) == $absRefPrefix) { + $sourcePath = substr($sourcePath, $absRefPrefixLength); + $localPath = PATH_site . $sourcePath; + if (!is_file($localPath)) { + $localPath = ''; + } + } + } + return $localPath; + } + /** + * Attempts to create a local file path from the absolute URL without + * schema. + * + * @param string $sourcePath + * @return string + */ + protected function createLocalPathFromAbsoluteURL($sourcePath) { + if ($sourcePath{0} == '/') { + $sourcePath = substr($sourcePath, 1); + $localPath = PATH_site . $sourcePath; + if (!is_file($localPath)) { + $localPath = ''; + } + } + return $localPath; + } - - - - - /****************************************** * * Indexing; external URL