* Retrieves the share record for a given token. * * @param string $token The share token. * @return array|null Returns the share record as an associative array, or null if not found. */
($token)
| 3005 | * @return array|null Returns the share record as an associative array, or null if not found. |
| 3006 | */ |
| 3007 | public static function getShareRecord($token) |
| 3008 | { |
| 3009 | $token = (string)$token; |
| 3010 | $readRecord = function (string $path, string $token): ?array { |
| 3011 | if (!is_file($path)) { |
| 3012 | return null; |
| 3013 | } |
| 3014 | $shareLinks = json_decode((string)@file_get_contents($path), true); |
| 3015 | if (!is_array($shareLinks) || !isset($shareLinks[$token])) { |
| 3016 | return null; |
| 3017 | } |
| 3018 | return $shareLinks[$token]; |
| 3019 | }; |
| 3020 | |
| 3021 | $currentId = class_exists('SourceContext') ? SourceContext::getActiveId() : ''; |
| 3022 | $shareFile = self::metaRoot() . "share_links.json"; |
| 3023 | $record = $readRecord($shareFile, $token); |
| 3024 | if ($record) { |
| 3025 | return $record; |
| 3026 | } |
| 3027 | |
| 3028 | if (!class_exists('SourceContext') || !SourceContext::sourcesEnabled()) { |
| 3029 | return null; |
| 3030 | } |
| 3031 | |
| 3032 | $sources = SourceContext::listAllSources(); |
| 3033 | foreach ($sources as $src) { |
| 3034 | if (isset($src['enabled']) && !$src['enabled']) { |
| 3035 | continue; |
| 3036 | } |
| 3037 | $id = (string)($src['id'] ?? ''); |
| 3038 | if ($id === '' || $id === $currentId) { |
| 3039 | continue; |
| 3040 | } |
| 3041 | $path = SourceContext::metaRootForId($id) . "share_links.json"; |
| 3042 | $record = $readRecord($path, $token); |
| 3043 | if ($record) { |
| 3044 | SourceContext::setActiveId($id, false); |
| 3045 | return $record; |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | return null; |
| 3050 | } |
| 3051 | |
| 3052 | /** |
| 3053 | * Creates a share link for a file. |
no test coverage detected