fileSystem = $fileSystem; } /** * Get file path from url. * @param null $url * @return string * @throws \tao_models_classes_FileNotFoundException */ public function getFilePathFromUrl($url) { $url = parse_url($url)['path']; //remove query part from url. $rel = substr($url, strpos($url, self::ENTRY_POINT) + strlen(self::ENTRY_POINT)); $parts = explode('/', $rel, 4); list ($webSourceId, $timestamp, $token, $subPath) = $parts; $parts = explode('*/', $subPath, 2); if (count($parts) < 2) { throw new \tao_models_classes_FileNotFoundException('`' . $subPath . '` - (wrong number of path parts)'); } list ($subPath, $file) = $parts; $secret = $this->getOption('secret'); $ttl = $this->getOption('ttl'); $correctToken = md5($timestamp . $subPath . $secret); if (time() - $timestamp > $ttl) { throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (file link expired)'); } if ($token != $correctToken) { throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (wrong token)'); } $path = []; foreach (explode('/', $subPath . $file) as $ele) { $path[] = rawurldecode($ele); } $filename = implode('/', $path); return $filename; } /** * @param string $relativePath * @return string * @throws \common_exception_Error * @throws \common_ext_ExtensionException */ public function getAccessUrl($relativePath) { $path = []; foreach (preg_split('/[\/\\\]/', ltrim($relativePath, '/\\')) as $ele) { $path[] = rawurlencode($ele); } $relUrl = implode('/', $path); $token = $this->generateToken($relUrl); $taoExtension = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); return $taoExtension->getConstant('BASE_URL') . 'getFileFlysystem.php/' . $this->getId() . '/' . $token . '/' . $relUrl . '*/'; } }