@@ -28,36 +28,36 @@ |
||
| 28 | 28 | * @since 25.0.0 |
| 29 | 29 | */ |
| 30 | 30 | interface IReferenceProvider { |
| 31 | - /** |
|
| 32 | - * Validate that a given reference identifier matches the current provider |
|
| 33 | - * |
|
| 34 | - * @since 25.0.0 |
|
| 35 | - */ |
|
| 36 | - public function matchReference(string $referenceText): bool; |
|
| 31 | + /** |
|
| 32 | + * Validate that a given reference identifier matches the current provider |
|
| 33 | + * |
|
| 34 | + * @since 25.0.0 |
|
| 35 | + */ |
|
| 36 | + public function matchReference(string $referenceText): bool; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Return a reference with its metadata for a given reference identifier |
|
| 40 | - * |
|
| 41 | - * @since 25.0.0 |
|
| 42 | - */ |
|
| 43 | - public function resolveReference(string $referenceText): ?IReference; |
|
| 38 | + /** |
|
| 39 | + * Return a reference with its metadata for a given reference identifier |
|
| 40 | + * |
|
| 41 | + * @since 25.0.0 |
|
| 42 | + */ |
|
| 43 | + public function resolveReference(string $referenceText): ?IReference; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Return true if the reference metadata can be globally cached |
|
| 47 | - * |
|
| 48 | - * @since 25.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getCachePrefix(string $referenceId): string; |
|
| 45 | + /** |
|
| 46 | + * Return true if the reference metadata can be globally cached |
|
| 47 | + * |
|
| 48 | + * @since 25.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getCachePrefix(string $referenceId): string; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return a custom cache key to be used for caching the metadata |
|
| 54 | - * This could be for example the current user id if the reference |
|
| 55 | - * access permissions are different for each user |
|
| 56 | - * |
|
| 57 | - * Should return null, if the cache is only related to the |
|
| 58 | - * reference id and has no further dependency |
|
| 59 | - * |
|
| 60 | - * @since 25.0.0 |
|
| 61 | - */ |
|
| 62 | - public function getCacheKey(string $referenceId): ?string; |
|
| 52 | + /** |
|
| 53 | + * Return a custom cache key to be used for caching the metadata |
|
| 54 | + * This could be for example the current user id if the reference |
|
| 55 | + * access permissions are different for each user |
|
| 56 | + * |
|
| 57 | + * Should return null, if the cache is only related to the |
|
| 58 | + * reference id and has no further dependency |
|
| 59 | + * |
|
| 60 | + * @since 25.0.0 |
|
| 61 | + */ |
|
| 62 | + public function getCacheKey(string $referenceId): ?string; |
|
| 63 | 63 | } |
@@ -28,43 +28,43 @@ |
||
| 28 | 28 | * @since 25.0.0 |
| 29 | 29 | */ |
| 30 | 30 | interface IReferenceManager { |
| 31 | - /** |
|
| 32 | - * Return all reference identifiers within a string as an array |
|
| 33 | - * |
|
| 34 | - * @return string[] Array of found references (urls) |
|
| 35 | - * @since 25.0.0 |
|
| 36 | - */ |
|
| 37 | - public function extractReferences(string $text): array; |
|
| 31 | + /** |
|
| 32 | + * Return all reference identifiers within a string as an array |
|
| 33 | + * |
|
| 34 | + * @return string[] Array of found references (urls) |
|
| 35 | + * @since 25.0.0 |
|
| 36 | + */ |
|
| 37 | + public function extractReferences(string $text): array; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Resolve a given reference id to its metadata with all available providers |
|
| 41 | - * |
|
| 42 | - * This method has a fallback to always provide the open graph metadata, |
|
| 43 | - * but may still return null in case this is disabled or the fetching fails |
|
| 44 | - * |
|
| 45 | - * @since 25.0.0 |
|
| 46 | - */ |
|
| 47 | - public function resolveReference(string $referenceId): ?IReference; |
|
| 39 | + /** |
|
| 40 | + * Resolve a given reference id to its metadata with all available providers |
|
| 41 | + * |
|
| 42 | + * This method has a fallback to always provide the open graph metadata, |
|
| 43 | + * but may still return null in case this is disabled or the fetching fails |
|
| 44 | + * |
|
| 45 | + * @since 25.0.0 |
|
| 46 | + */ |
|
| 47 | + public function resolveReference(string $referenceId): ?IReference; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Get a reference by its cache key |
|
| 51 | - * |
|
| 52 | - * @since 25.0.0 |
|
| 53 | - */ |
|
| 54 | - public function getReferenceByCacheKey(string $cacheKey): ?IReference; |
|
| 49 | + /** |
|
| 50 | + * Get a reference by its cache key |
|
| 51 | + * |
|
| 52 | + * @since 25.0.0 |
|
| 53 | + */ |
|
| 54 | + public function getReferenceByCacheKey(string $cacheKey): ?IReference; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Explicitly get a reference from the cache to avoid heavy fetches for cases |
|
| 58 | - * the cache can then be filled with a separate request from the frontend |
|
| 59 | - * |
|
| 60 | - * @since 25.0.0 |
|
| 61 | - */ |
|
| 62 | - public function getReferenceFromCache(string $referenceId): ?IReference; |
|
| 56 | + /** |
|
| 57 | + * Explicitly get a reference from the cache to avoid heavy fetches for cases |
|
| 58 | + * the cache can then be filled with a separate request from the frontend |
|
| 59 | + * |
|
| 60 | + * @since 25.0.0 |
|
| 61 | + */ |
|
| 62 | + public function getReferenceFromCache(string $referenceId): ?IReference; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Invalidate all cache entries with a prefix or just one if the cache key is provided |
|
| 66 | - * |
|
| 67 | - * @since 25.0.0 |
|
| 68 | - */ |
|
| 69 | - public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void; |
|
| 64 | + /** |
|
| 65 | + * Invalidate all cache entries with a prefix or just one if the cache key is provided |
|
| 66 | + * |
|
| 67 | + * @since 25.0.0 |
|
| 68 | + */ |
|
| 69 | + public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void; |
|
| 70 | 70 | } |
@@ -31,100 +31,100 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | interface IReference extends JsonSerializable { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @since 25.0.0 |
|
| 36 | - */ |
|
| 37 | - public function getId(): string; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Accessible flag indicates if the user has access to the provided reference |
|
| 41 | - * |
|
| 42 | - * @since 25.0.0 |
|
| 43 | - */ |
|
| 44 | - public function setAccessible(bool $accessible): void; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Accessible flag indicates if the user has access to the provided reference |
|
| 48 | - * |
|
| 49 | - * @since 25.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getAccessible(): bool; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @since 25.0.0 |
|
| 55 | - */ |
|
| 56 | - public function setTitle(string $title): void; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @since 25.0.0 |
|
| 60 | - */ |
|
| 61 | - public function getTitle(): string; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @since 25.0.0 |
|
| 65 | - */ |
|
| 66 | - public function setDescription(?string $description): void; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @since 25.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getDescription(): ?string; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @since 25.0.0 |
|
| 75 | - */ |
|
| 76 | - public function setImageUrl(?string $imageUrl): void; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @since 25.0.0 |
|
| 80 | - */ |
|
| 81 | - public function getImageUrl(): ?string; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @since 25.0.0 |
|
| 85 | - */ |
|
| 86 | - public function setImageContentType(?string $contentType): void; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @since 25.0.0 |
|
| 90 | - */ |
|
| 91 | - public function getImageContentType(): ?string; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @since 25.0.0 |
|
| 95 | - */ |
|
| 96 | - public function setUrl(?string $url): void; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @since 25.0.0 |
|
| 100 | - */ |
|
| 101 | - public function getUrl(): ?string; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Set the reference specific rich object representation |
|
| 105 | - * |
|
| 106 | - * @since 25.0.0 |
|
| 107 | - */ |
|
| 108 | - public function setRichObject(string $type, ?array $richObject): void; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Returns the type of the reference specific rich object |
|
| 112 | - * |
|
| 113 | - * @since 25.0.0 |
|
| 114 | - */ |
|
| 115 | - public function getRichObjectType(): string; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Returns the reference specific rich object representation |
|
| 119 | - * |
|
| 120 | - * @since 25.0.0 |
|
| 121 | - */ |
|
| 122 | - public function getRichObject(): array; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Returns the opengraph rich object representation |
|
| 126 | - * |
|
| 127 | - * @since 25.0.0 |
|
| 128 | - */ |
|
| 129 | - public function getOpenGraphObject(): array; |
|
| 34 | + /** |
|
| 35 | + * @since 25.0.0 |
|
| 36 | + */ |
|
| 37 | + public function getId(): string; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Accessible flag indicates if the user has access to the provided reference |
|
| 41 | + * |
|
| 42 | + * @since 25.0.0 |
|
| 43 | + */ |
|
| 44 | + public function setAccessible(bool $accessible): void; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Accessible flag indicates if the user has access to the provided reference |
|
| 48 | + * |
|
| 49 | + * @since 25.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getAccessible(): bool; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @since 25.0.0 |
|
| 55 | + */ |
|
| 56 | + public function setTitle(string $title): void; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @since 25.0.0 |
|
| 60 | + */ |
|
| 61 | + public function getTitle(): string; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @since 25.0.0 |
|
| 65 | + */ |
|
| 66 | + public function setDescription(?string $description): void; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @since 25.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getDescription(): ?string; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @since 25.0.0 |
|
| 75 | + */ |
|
| 76 | + public function setImageUrl(?string $imageUrl): void; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @since 25.0.0 |
|
| 80 | + */ |
|
| 81 | + public function getImageUrl(): ?string; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @since 25.0.0 |
|
| 85 | + */ |
|
| 86 | + public function setImageContentType(?string $contentType): void; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @since 25.0.0 |
|
| 90 | + */ |
|
| 91 | + public function getImageContentType(): ?string; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @since 25.0.0 |
|
| 95 | + */ |
|
| 96 | + public function setUrl(?string $url): void; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @since 25.0.0 |
|
| 100 | + */ |
|
| 101 | + public function getUrl(): ?string; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Set the reference specific rich object representation |
|
| 105 | + * |
|
| 106 | + * @since 25.0.0 |
|
| 107 | + */ |
|
| 108 | + public function setRichObject(string $type, ?array $richObject): void; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Returns the type of the reference specific rich object |
|
| 112 | + * |
|
| 113 | + * @since 25.0.0 |
|
| 114 | + */ |
|
| 115 | + public function getRichObjectType(): string; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Returns the reference specific rich object representation |
|
| 119 | + * |
|
| 120 | + * @since 25.0.0 |
|
| 121 | + */ |
|
| 122 | + public function getRichObject(): array; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Returns the opengraph rich object representation |
|
| 126 | + * |
|
| 127 | + * @since 25.0.0 |
|
| 128 | + */ |
|
| 129 | + public function getOpenGraphObject(): array; |
|
| 130 | 130 | } |
@@ -36,94 +36,94 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | interface IURLGenerator { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Regex for matching http(s) urls |
|
| 41 | - * |
|
| 42 | - * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing |
|
| 43 | - * |
|
| 44 | - * @since 25.0.0 |
|
| 45 | - */ |
|
| 46 | - public const URL_REGEX = '/(\s|\n|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)/mi'; |
|
| 39 | + /** |
|
| 40 | + * Regex for matching http(s) urls |
|
| 41 | + * |
|
| 42 | + * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing |
|
| 43 | + * |
|
| 44 | + * @since 25.0.0 |
|
| 45 | + */ |
|
| 46 | + public const URL_REGEX = '/(\s|\n|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)/mi'; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Returns the URL for a route |
|
| 50 | - * @param string $routeName the name of the route |
|
| 51 | - * @param array $arguments an array with arguments which will be filled into the url |
|
| 52 | - * @return string the url |
|
| 53 | - * @since 6.0.0 |
|
| 54 | - */ |
|
| 55 | - public function linkToRoute(string $routeName, array $arguments = []): string; |
|
| 48 | + /** |
|
| 49 | + * Returns the URL for a route |
|
| 50 | + * @param string $routeName the name of the route |
|
| 51 | + * @param array $arguments an array with arguments which will be filled into the url |
|
| 52 | + * @return string the url |
|
| 53 | + * @since 6.0.0 |
|
| 54 | + */ |
|
| 55 | + public function linkToRoute(string $routeName, array $arguments = []): string; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Returns the absolute URL for a route |
|
| 59 | - * @param string $routeName the name of the route |
|
| 60 | - * @param array $arguments an array with arguments which will be filled into the url |
|
| 61 | - * @return string the absolute url |
|
| 62 | - * @since 8.0.0 |
|
| 63 | - */ |
|
| 64 | - public function linkToRouteAbsolute(string $routeName, array $arguments = []): string; |
|
| 57 | + /** |
|
| 58 | + * Returns the absolute URL for a route |
|
| 59 | + * @param string $routeName the name of the route |
|
| 60 | + * @param array $arguments an array with arguments which will be filled into the url |
|
| 61 | + * @return string the absolute url |
|
| 62 | + * @since 8.0.0 |
|
| 63 | + */ |
|
| 64 | + public function linkToRouteAbsolute(string $routeName, array $arguments = []): string; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $routeName |
|
| 68 | - * @param array $arguments |
|
| 69 | - * @return string |
|
| 70 | - * @since 15.0.0 |
|
| 71 | - */ |
|
| 72 | - public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string; |
|
| 66 | + /** |
|
| 67 | + * @param string $routeName |
|
| 68 | + * @param array $arguments |
|
| 69 | + * @return string |
|
| 70 | + * @since 15.0.0 |
|
| 71 | + */ |
|
| 72 | + public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Returns an URL for an image or file |
|
| 76 | - * @param string $appName the name of the app |
|
| 77 | - * @param string $file the name of the file |
|
| 78 | - * @param array $args array with param=>value, will be appended to the returned url |
|
| 79 | - * The value of $args will be urlencoded |
|
| 80 | - * @return string the url |
|
| 81 | - * @since 6.0.0 |
|
| 82 | - */ |
|
| 83 | - public function linkTo(string $appName, string $file, array $args = []): string; |
|
| 74 | + /** |
|
| 75 | + * Returns an URL for an image or file |
|
| 76 | + * @param string $appName the name of the app |
|
| 77 | + * @param string $file the name of the file |
|
| 78 | + * @param array $args array with param=>value, will be appended to the returned url |
|
| 79 | + * The value of $args will be urlencoded |
|
| 80 | + * @return string the url |
|
| 81 | + * @since 6.0.0 |
|
| 82 | + */ |
|
| 83 | + public function linkTo(string $appName, string $file, array $args = []): string; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Returns the link to an image, like linkTo but only with prepending img/ |
|
| 87 | - * @param string $appName the name of the app |
|
| 88 | - * @param string $file the name of the file |
|
| 89 | - * @return string the url |
|
| 90 | - * @since 6.0.0 |
|
| 91 | - */ |
|
| 92 | - public function imagePath(string $appName, string $file): string; |
|
| 85 | + /** |
|
| 86 | + * Returns the link to an image, like linkTo but only with prepending img/ |
|
| 87 | + * @param string $appName the name of the app |
|
| 88 | + * @param string $file the name of the file |
|
| 89 | + * @return string the url |
|
| 90 | + * @since 6.0.0 |
|
| 91 | + */ |
|
| 92 | + public function imagePath(string $appName, string $file): string; |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Makes an URL absolute |
|
| 97 | - * @param string $url the url in the ownCloud host |
|
| 98 | - * @return string the absolute version of the url |
|
| 99 | - * @since 6.0.0 |
|
| 100 | - */ |
|
| 101 | - public function getAbsoluteURL(string $url): string; |
|
| 95 | + /** |
|
| 96 | + * Makes an URL absolute |
|
| 97 | + * @param string $url the url in the ownCloud host |
|
| 98 | + * @return string the absolute version of the url |
|
| 99 | + * @since 6.0.0 |
|
| 100 | + */ |
|
| 101 | + public function getAbsoluteURL(string $url): string; |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @param string $key |
|
| 105 | - * @return string url to the online documentation |
|
| 106 | - * @since 8.0.0 |
|
| 107 | - */ |
|
| 108 | - public function linkToDocs(string $key): string; |
|
| 103 | + /** |
|
| 104 | + * @param string $key |
|
| 105 | + * @return string url to the online documentation |
|
| 106 | + * @since 8.0.0 |
|
| 107 | + */ |
|
| 108 | + public function linkToDocs(string $key): string; |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Returns the URL of the default page based on the system configuration |
|
| 112 | - * and the apps visible for the current user |
|
| 113 | - * @return string |
|
| 114 | - * @since 23.0.0 |
|
| 115 | - */ |
|
| 116 | - public function linkToDefaultPageUrl(): string; |
|
| 110 | + /** |
|
| 111 | + * Returns the URL of the default page based on the system configuration |
|
| 112 | + * and the apps visible for the current user |
|
| 113 | + * @return string |
|
| 114 | + * @since 23.0.0 |
|
| 115 | + */ |
|
| 116 | + public function linkToDefaultPageUrl(): string; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @return string base url of the current request |
|
| 120 | - * @since 13.0.0 |
|
| 121 | - */ |
|
| 122 | - public function getBaseUrl(): string; |
|
| 118 | + /** |
|
| 119 | + * @return string base url of the current request |
|
| 120 | + * @since 13.0.0 |
|
| 121 | + */ |
|
| 122 | + public function getBaseUrl(): string; |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return string webroot part of the base url |
|
| 126 | - * @since 23.0.0 |
|
| 127 | - */ |
|
| 128 | - public function getWebroot(): string; |
|
| 124 | + /** |
|
| 125 | + * @return string webroot part of the base url |
|
| 126 | + * @since 23.0.0 |
|
| 127 | + */ |
|
| 128 | + public function getWebroot(): string; |
|
| 129 | 129 | } |
@@ -48,283 +48,283 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | interface IRegistrationContext { |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $capability |
|
| 53 | - * @psalm-param class-string<ICapability> $capability |
|
| 54 | - * @see IAppContainer::registerCapability |
|
| 55 | - * |
|
| 56 | - * @since 20.0.0 |
|
| 57 | - */ |
|
| 58 | - public function registerCapability(string $capability): void; |
|
| 51 | + /** |
|
| 52 | + * @param string $capability |
|
| 53 | + * @psalm-param class-string<ICapability> $capability |
|
| 54 | + * @see IAppContainer::registerCapability |
|
| 55 | + * |
|
| 56 | + * @since 20.0.0 |
|
| 57 | + */ |
|
| 58 | + public function registerCapability(string $capability): void; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Register an implementation of \OCP\Support\CrashReport\IReporter that |
|
| 62 | - * will receive unhandled exceptions and throwables |
|
| 63 | - * |
|
| 64 | - * @param string $reporterClass |
|
| 65 | - * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass |
|
| 66 | - * @return void |
|
| 67 | - * @since 20.0.0 |
|
| 68 | - */ |
|
| 69 | - public function registerCrashReporter(string $reporterClass): void; |
|
| 60 | + /** |
|
| 61 | + * Register an implementation of \OCP\Support\CrashReport\IReporter that |
|
| 62 | + * will receive unhandled exceptions and throwables |
|
| 63 | + * |
|
| 64 | + * @param string $reporterClass |
|
| 65 | + * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass |
|
| 66 | + * @return void |
|
| 67 | + * @since 20.0.0 |
|
| 68 | + */ |
|
| 69 | + public function registerCrashReporter(string $reporterClass): void; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Register an implementation of \OCP\Dashboard\IWidget that |
|
| 73 | - * will handle the implementation of a dashboard widget |
|
| 74 | - * |
|
| 75 | - * @param string $widgetClass |
|
| 76 | - * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass |
|
| 77 | - * @return void |
|
| 78 | - * @since 20.0.0 |
|
| 79 | - */ |
|
| 80 | - public function registerDashboardWidget(string $widgetClass): void; |
|
| 71 | + /** |
|
| 72 | + * Register an implementation of \OCP\Dashboard\IWidget that |
|
| 73 | + * will handle the implementation of a dashboard widget |
|
| 74 | + * |
|
| 75 | + * @param string $widgetClass |
|
| 76 | + * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass |
|
| 77 | + * @return void |
|
| 78 | + * @since 20.0.0 |
|
| 79 | + */ |
|
| 80 | + public function registerDashboardWidget(string $widgetClass): void; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Register a service |
|
| 84 | - * |
|
| 85 | - * @param string $name |
|
| 86 | - * @param callable $factory |
|
| 87 | - * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory |
|
| 88 | - * @param bool $shared |
|
| 89 | - * |
|
| 90 | - * @return void |
|
| 91 | - * @see IContainer::registerService() |
|
| 92 | - * |
|
| 93 | - * @since 20.0.0 |
|
| 94 | - */ |
|
| 95 | - public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
| 82 | + /** |
|
| 83 | + * Register a service |
|
| 84 | + * |
|
| 85 | + * @param string $name |
|
| 86 | + * @param callable $factory |
|
| 87 | + * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory |
|
| 88 | + * @param bool $shared |
|
| 89 | + * |
|
| 90 | + * @return void |
|
| 91 | + * @see IContainer::registerService() |
|
| 92 | + * |
|
| 93 | + * @since 20.0.0 |
|
| 94 | + */ |
|
| 95 | + public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @param string $alias |
|
| 99 | - * @psalm-param string|class-string $alias |
|
| 100 | - * @param string $target |
|
| 101 | - * @psalm-param string|class-string $target |
|
| 102 | - * |
|
| 103 | - * @return void |
|
| 104 | - * @see IContainer::registerAlias() |
|
| 105 | - * |
|
| 106 | - * @since 20.0.0 |
|
| 107 | - */ |
|
| 108 | - public function registerServiceAlias(string $alias, string $target): void; |
|
| 97 | + /** |
|
| 98 | + * @param string $alias |
|
| 99 | + * @psalm-param string|class-string $alias |
|
| 100 | + * @param string $target |
|
| 101 | + * @psalm-param string|class-string $target |
|
| 102 | + * |
|
| 103 | + * @return void |
|
| 104 | + * @see IContainer::registerAlias() |
|
| 105 | + * |
|
| 106 | + * @since 20.0.0 |
|
| 107 | + */ |
|
| 108 | + public function registerServiceAlias(string $alias, string $target): void; |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @param string $name |
|
| 112 | - * @param mixed $value |
|
| 113 | - * |
|
| 114 | - * @return void |
|
| 115 | - * @see IContainer::registerParameter() |
|
| 116 | - * |
|
| 117 | - * @since 20.0.0 |
|
| 118 | - */ |
|
| 119 | - public function registerParameter(string $name, $value): void; |
|
| 110 | + /** |
|
| 111 | + * @param string $name |
|
| 112 | + * @param mixed $value |
|
| 113 | + * |
|
| 114 | + * @return void |
|
| 115 | + * @see IContainer::registerParameter() |
|
| 116 | + * |
|
| 117 | + * @since 20.0.0 |
|
| 118 | + */ |
|
| 119 | + public function registerParameter(string $name, $value): void; |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Register a service listener |
|
| 123 | - * |
|
| 124 | - * This is equivalent to calling IEventDispatcher::addServiceListener |
|
| 125 | - * |
|
| 126 | - * @psalm-template T of \OCP\EventDispatcher\Event |
|
| 127 | - * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 128 | - * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 129 | - * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 130 | - * @psalm-param class-string<\OCP\EventDispatcher\IEventListener> $listener fully qualified class name that can be built by the DI container |
|
| 131 | - * @param int $priority The higher this value, the earlier an event |
|
| 132 | - * listener will be triggered in the chain (defaults to 0) |
|
| 133 | - * |
|
| 134 | - * @see IEventDispatcher::addServiceListener() |
|
| 135 | - * |
|
| 136 | - * @since 20.0.0 |
|
| 137 | - */ |
|
| 138 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
| 121 | + /** |
|
| 122 | + * Register a service listener |
|
| 123 | + * |
|
| 124 | + * This is equivalent to calling IEventDispatcher::addServiceListener |
|
| 125 | + * |
|
| 126 | + * @psalm-template T of \OCP\EventDispatcher\Event |
|
| 127 | + * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 128 | + * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 129 | + * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 130 | + * @psalm-param class-string<\OCP\EventDispatcher\IEventListener> $listener fully qualified class name that can be built by the DI container |
|
| 131 | + * @param int $priority The higher this value, the earlier an event |
|
| 132 | + * listener will be triggered in the chain (defaults to 0) |
|
| 133 | + * |
|
| 134 | + * @see IEventDispatcher::addServiceListener() |
|
| 135 | + * |
|
| 136 | + * @since 20.0.0 |
|
| 137 | + */ |
|
| 138 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @param string $class |
|
| 142 | - * @psalm-param class-string<\OCP\AppFramework\Middleware> $class |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - * @see IAppContainer::registerMiddleWare() |
|
| 146 | - * |
|
| 147 | - * @since 20.0.0 |
|
| 148 | - */ |
|
| 149 | - public function registerMiddleware(string $class): void; |
|
| 140 | + /** |
|
| 141 | + * @param string $class |
|
| 142 | + * @psalm-param class-string<\OCP\AppFramework\Middleware> $class |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + * @see IAppContainer::registerMiddleWare() |
|
| 146 | + * |
|
| 147 | + * @since 20.0.0 |
|
| 148 | + */ |
|
| 149 | + public function registerMiddleware(string $class): void; |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Register a search provider for the unified search |
|
| 153 | - * |
|
| 154 | - * It is allowed to register more than one provider per app as the search |
|
| 155 | - * results can go into distinct sections, e.g. "Files" and "Files shared |
|
| 156 | - * with you" in the Files app. |
|
| 157 | - * |
|
| 158 | - * @param string $class |
|
| 159 | - * @psalm-param class-string<\OCP\Search\IProvider> $class |
|
| 160 | - * |
|
| 161 | - * @return void |
|
| 162 | - * |
|
| 163 | - * @since 20.0.0 |
|
| 164 | - */ |
|
| 165 | - public function registerSearchProvider(string $class): void; |
|
| 151 | + /** |
|
| 152 | + * Register a search provider for the unified search |
|
| 153 | + * |
|
| 154 | + * It is allowed to register more than one provider per app as the search |
|
| 155 | + * results can go into distinct sections, e.g. "Files" and "Files shared |
|
| 156 | + * with you" in the Files app. |
|
| 157 | + * |
|
| 158 | + * @param string $class |
|
| 159 | + * @psalm-param class-string<\OCP\Search\IProvider> $class |
|
| 160 | + * |
|
| 161 | + * @return void |
|
| 162 | + * |
|
| 163 | + * @since 20.0.0 |
|
| 164 | + */ |
|
| 165 | + public function registerSearchProvider(string $class): void; |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Register an alternative login option |
|
| 169 | - * |
|
| 170 | - * It is allowed to register more than one option per app. |
|
| 171 | - * |
|
| 172 | - * @param string $class |
|
| 173 | - * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class |
|
| 174 | - * |
|
| 175 | - * @return void |
|
| 176 | - * |
|
| 177 | - * @since 20.0.0 |
|
| 178 | - */ |
|
| 179 | - public function registerAlternativeLogin(string $class): void; |
|
| 167 | + /** |
|
| 168 | + * Register an alternative login option |
|
| 169 | + * |
|
| 170 | + * It is allowed to register more than one option per app. |
|
| 171 | + * |
|
| 172 | + * @param string $class |
|
| 173 | + * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class |
|
| 174 | + * |
|
| 175 | + * @return void |
|
| 176 | + * |
|
| 177 | + * @since 20.0.0 |
|
| 178 | + */ |
|
| 179 | + public function registerAlternativeLogin(string $class): void; |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Register an initialstate provider |
|
| 183 | - * |
|
| 184 | - * It is allowed to register more than one provider per app. |
|
| 185 | - * |
|
| 186 | - * @param string $class |
|
| 187 | - * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class |
|
| 188 | - * |
|
| 189 | - * @return void |
|
| 190 | - * |
|
| 191 | - * @since 21.0.0 |
|
| 192 | - */ |
|
| 193 | - public function registerInitialStateProvider(string $class): void; |
|
| 181 | + /** |
|
| 182 | + * Register an initialstate provider |
|
| 183 | + * |
|
| 184 | + * It is allowed to register more than one provider per app. |
|
| 185 | + * |
|
| 186 | + * @param string $class |
|
| 187 | + * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class |
|
| 188 | + * |
|
| 189 | + * @return void |
|
| 190 | + * |
|
| 191 | + * @since 21.0.0 |
|
| 192 | + */ |
|
| 193 | + public function registerInitialStateProvider(string $class): void; |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Register a well known protocol handler |
|
| 197 | - * |
|
| 198 | - * It is allowed to register more than one handler per app. |
|
| 199 | - * |
|
| 200 | - * @param string $class |
|
| 201 | - * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class |
|
| 202 | - * |
|
| 203 | - * @return void |
|
| 204 | - * |
|
| 205 | - * @since 21.0.0 |
|
| 206 | - */ |
|
| 207 | - public function registerWellKnownHandler(string $class): void; |
|
| 195 | + /** |
|
| 196 | + * Register a well known protocol handler |
|
| 197 | + * |
|
| 198 | + * It is allowed to register more than one handler per app. |
|
| 199 | + * |
|
| 200 | + * @param string $class |
|
| 201 | + * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class |
|
| 202 | + * |
|
| 203 | + * @return void |
|
| 204 | + * |
|
| 205 | + * @since 21.0.0 |
|
| 206 | + */ |
|
| 207 | + public function registerWellKnownHandler(string $class): void; |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Register a custom template provider class that is able to inject custom templates |
|
| 211 | - * in addition to the user defined ones |
|
| 212 | - * |
|
| 213 | - * @param string $providerClass |
|
| 214 | - * @psalm-param class-string<ICustomTemplateProvider> $providerClass |
|
| 215 | - * @since 21.0.0 |
|
| 216 | - */ |
|
| 217 | - public function registerTemplateProvider(string $providerClass): void; |
|
| 209 | + /** |
|
| 210 | + * Register a custom template provider class that is able to inject custom templates |
|
| 211 | + * in addition to the user defined ones |
|
| 212 | + * |
|
| 213 | + * @param string $providerClass |
|
| 214 | + * @psalm-param class-string<ICustomTemplateProvider> $providerClass |
|
| 215 | + * @since 21.0.0 |
|
| 216 | + */ |
|
| 217 | + public function registerTemplateProvider(string $providerClass): void; |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Register an INotifier class |
|
| 221 | - * |
|
| 222 | - * @param string $notifierClass |
|
| 223 | - * @psalm-param class-string<INotifier> $notifierClass |
|
| 224 | - * @since 22.0.0 |
|
| 225 | - */ |
|
| 226 | - public function registerNotifierService(string $notifierClass): void; |
|
| 219 | + /** |
|
| 220 | + * Register an INotifier class |
|
| 221 | + * |
|
| 222 | + * @param string $notifierClass |
|
| 223 | + * @psalm-param class-string<INotifier> $notifierClass |
|
| 224 | + * @since 22.0.0 |
|
| 225 | + */ |
|
| 226 | + public function registerNotifierService(string $notifierClass): void; |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Register a two-factor provider |
|
| 230 | - * |
|
| 231 | - * @param string $twoFactorProviderClass |
|
| 232 | - * @psalm-param class-string<IProvider> $twoFactorProviderClass |
|
| 233 | - * @since 22.0.0 |
|
| 234 | - */ |
|
| 235 | - public function registerTwoFactorProvider(string $twoFactorProviderClass): void; |
|
| 228 | + /** |
|
| 229 | + * Register a two-factor provider |
|
| 230 | + * |
|
| 231 | + * @param string $twoFactorProviderClass |
|
| 232 | + * @psalm-param class-string<IProvider> $twoFactorProviderClass |
|
| 233 | + * @since 22.0.0 |
|
| 234 | + */ |
|
| 235 | + public function registerTwoFactorProvider(string $twoFactorProviderClass): void; |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Register a preview provider |
|
| 239 | - * |
|
| 240 | - * It is allowed to register more than one provider per app. |
|
| 241 | - * |
|
| 242 | - * @param string $previewProviderClass |
|
| 243 | - * @param string $mimeTypeRegex |
|
| 244 | - * @psalm-param class-string<IProviderV2> $previewProviderClass |
|
| 245 | - * @since 23.0.0 |
|
| 246 | - */ |
|
| 247 | - public function registerPreviewProvider(string $previewProviderClass, string $mimeTypeRegex): void; |
|
| 237 | + /** |
|
| 238 | + * Register a preview provider |
|
| 239 | + * |
|
| 240 | + * It is allowed to register more than one provider per app. |
|
| 241 | + * |
|
| 242 | + * @param string $previewProviderClass |
|
| 243 | + * @param string $mimeTypeRegex |
|
| 244 | + * @psalm-param class-string<IProviderV2> $previewProviderClass |
|
| 245 | + * @since 23.0.0 |
|
| 246 | + */ |
|
| 247 | + public function registerPreviewProvider(string $previewProviderClass, string $mimeTypeRegex): void; |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Register a calendar provider |
|
| 251 | - * |
|
| 252 | - * @param string $class |
|
| 253 | - * @psalm-param class-string<ICalendarProvider> $class |
|
| 254 | - * @since 23.0.0 |
|
| 255 | - */ |
|
| 256 | - public function registerCalendarProvider(string $class): void; |
|
| 249 | + /** |
|
| 250 | + * Register a calendar provider |
|
| 251 | + * |
|
| 252 | + * @param string $class |
|
| 253 | + * @psalm-param class-string<ICalendarProvider> $class |
|
| 254 | + * @since 23.0.0 |
|
| 255 | + */ |
|
| 256 | + public function registerCalendarProvider(string $class): void; |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Register a reference provider |
|
| 260 | - * |
|
| 261 | - * @param string $class |
|
| 262 | - * @psalm-param class-string<IReferenceProvider> $class |
|
| 263 | - * @since 25.0.0 |
|
| 264 | - */ |
|
| 265 | - public function registerReferenceProvider(string $class): void; |
|
| 258 | + /** |
|
| 259 | + * Register a reference provider |
|
| 260 | + * |
|
| 261 | + * @param string $class |
|
| 262 | + * @psalm-param class-string<IReferenceProvider> $class |
|
| 263 | + * @since 25.0.0 |
|
| 264 | + */ |
|
| 265 | + public function registerReferenceProvider(string $class): void; |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Register an implementation of \OCP\Profile\ILinkAction that |
|
| 269 | - * will handle the implementation of a profile link action |
|
| 270 | - * |
|
| 271 | - * @param string $actionClass |
|
| 272 | - * @psalm-param class-string<\OCP\Profile\ILinkAction> $actionClass |
|
| 273 | - * @return void |
|
| 274 | - * @since 23.0.0 |
|
| 275 | - */ |
|
| 276 | - public function registerProfileLinkAction(string $actionClass): void; |
|
| 267 | + /** |
|
| 268 | + * Register an implementation of \OCP\Profile\ILinkAction that |
|
| 269 | + * will handle the implementation of a profile link action |
|
| 270 | + * |
|
| 271 | + * @param string $actionClass |
|
| 272 | + * @psalm-param class-string<\OCP\Profile\ILinkAction> $actionClass |
|
| 273 | + * @return void |
|
| 274 | + * @since 23.0.0 |
|
| 275 | + */ |
|
| 276 | + public function registerProfileLinkAction(string $actionClass): void; |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * Register the backend of the Talk app |
|
| 280 | - * |
|
| 281 | - * This service must only be used by the Talk app |
|
| 282 | - * |
|
| 283 | - * @param string $backend |
|
| 284 | - * @return void |
|
| 285 | - * @since 24.0.0 |
|
| 286 | - */ |
|
| 287 | - public function registerTalkBackend(string $backend): void; |
|
| 278 | + /** |
|
| 279 | + * Register the backend of the Talk app |
|
| 280 | + * |
|
| 281 | + * This service must only be used by the Talk app |
|
| 282 | + * |
|
| 283 | + * @param string $backend |
|
| 284 | + * @return void |
|
| 285 | + * @since 24.0.0 |
|
| 286 | + */ |
|
| 287 | + public function registerTalkBackend(string $backend): void; |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * Register a resource backend for the DAV server |
|
| 291 | - * |
|
| 292 | - * @param string $actionClass |
|
| 293 | - * @psalm-param class-string<\OCP\Calendar\Resource\IBackend> $actionClass |
|
| 294 | - * @return void |
|
| 295 | - * @since 24.0.0 |
|
| 296 | - */ |
|
| 297 | - public function registerCalendarResourceBackend(string $class): void; |
|
| 289 | + /** |
|
| 290 | + * Register a resource backend for the DAV server |
|
| 291 | + * |
|
| 292 | + * @param string $actionClass |
|
| 293 | + * @psalm-param class-string<\OCP\Calendar\Resource\IBackend> $actionClass |
|
| 294 | + * @return void |
|
| 295 | + * @since 24.0.0 |
|
| 296 | + */ |
|
| 297 | + public function registerCalendarResourceBackend(string $class): void; |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Register a room backend for the DAV server |
|
| 301 | - * |
|
| 302 | - * @param string $actionClass |
|
| 303 | - * @psalm-param class-string<\OCP\Calendar\Room\IBackend> $actionClass |
|
| 304 | - * @return void |
|
| 305 | - * @since 24.0.0 |
|
| 306 | - */ |
|
| 307 | - public function registerCalendarRoomBackend(string $class): void; |
|
| 299 | + /** |
|
| 300 | + * Register a room backend for the DAV server |
|
| 301 | + * |
|
| 302 | + * @param string $actionClass |
|
| 303 | + * @psalm-param class-string<\OCP\Calendar\Room\IBackend> $actionClass |
|
| 304 | + * @return void |
|
| 305 | + * @since 24.0.0 |
|
| 306 | + */ |
|
| 307 | + public function registerCalendarRoomBackend(string $class): void; |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Register an implementation of \OCP\UserMigration\IMigrator that |
|
| 311 | - * will handle the implementation of a migrator |
|
| 312 | - * |
|
| 313 | - * @param string $migratorClass |
|
| 314 | - * @psalm-param class-string<\OCP\UserMigration\IMigrator> $migratorClass |
|
| 315 | - * @return void |
|
| 316 | - * @since 24.0.0 |
|
| 317 | - */ |
|
| 318 | - public function registerUserMigrator(string $migratorClass): void; |
|
| 309 | + /** |
|
| 310 | + * Register an implementation of \OCP\UserMigration\IMigrator that |
|
| 311 | + * will handle the implementation of a migrator |
|
| 312 | + * |
|
| 313 | + * @param string $migratorClass |
|
| 314 | + * @psalm-param class-string<\OCP\UserMigration\IMigrator> $migratorClass |
|
| 315 | + * @return void |
|
| 316 | + * @since 24.0.0 |
|
| 317 | + */ |
|
| 318 | + public function registerUserMigrator(string $migratorClass): void; |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Announce methods of classes that may contain sensitive values, which |
|
| 322 | - * should be obfuscated before being logged. |
|
| 323 | - * |
|
| 324 | - * @param string $class |
|
| 325 | - * @param string[] $methods |
|
| 326 | - * @return void |
|
| 327 | - * @since 25.0.0 |
|
| 328 | - */ |
|
| 329 | - public function registerSensitiveMethods(string $class, array $methods): void; |
|
| 320 | + /** |
|
| 321 | + * Announce methods of classes that may contain sensitive values, which |
|
| 322 | + * should be obfuscated before being logged. |
|
| 323 | + * |
|
| 324 | + * @param string $class |
|
| 325 | + * @param string[] $methods |
|
| 326 | + * @return void |
|
| 327 | + * @since 25.0.0 |
|
| 328 | + */ |
|
| 329 | + public function registerSensitiveMethods(string $class, array $methods): void; |
|
| 330 | 330 | } |
@@ -41,122 +41,122 @@ |
||
| 41 | 41 | use Psr\Log\LoggerInterface; |
| 42 | 42 | |
| 43 | 43 | class LinkReferenceProvider implements IReferenceProvider { |
| 44 | - public const MAX_PREVIEW_SIZE = 1024 * 1024; |
|
| 45 | - |
|
| 46 | - public const ALLOWED_CONTENT_TYPES = [ |
|
| 47 | - 'image/png', |
|
| 48 | - 'image/jpg', |
|
| 49 | - 'image/jpeg', |
|
| 50 | - 'image/gif', |
|
| 51 | - 'image/svg+xml', |
|
| 52 | - 'image/webp' |
|
| 53 | - ]; |
|
| 54 | - |
|
| 55 | - private IClientService $clientService; |
|
| 56 | - private LoggerInterface $logger; |
|
| 57 | - private SystemConfig $systemConfig; |
|
| 58 | - private IAppDataFactory $appDataFactory; |
|
| 59 | - private IURLGenerator $urlGenerator; |
|
| 60 | - private Limiter $limiter; |
|
| 61 | - private IUserSession $userSession; |
|
| 62 | - private IRequest $request; |
|
| 63 | - |
|
| 64 | - public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator, Limiter $limiter, IUserSession $userSession, IRequest $request) { |
|
| 65 | - $this->clientService = $clientService; |
|
| 66 | - $this->logger = $logger; |
|
| 67 | - $this->systemConfig = $systemConfig; |
|
| 68 | - $this->appDataFactory = $appDataFactory; |
|
| 69 | - $this->urlGenerator = $urlGenerator; |
|
| 70 | - $this->limiter = $limiter; |
|
| 71 | - $this->userSession = $userSession; |
|
| 72 | - $this->request = $request; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function matchReference(string $referenceText): bool { |
|
| 76 | - if ($this->systemConfig->getValue('reference_opengraph', true) !== true) { |
|
| 77 | - return false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return (bool)preg_match(IURLGenerator::URL_REGEX, $referenceText); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function resolveReference(string $referenceText): ?IReference { |
|
| 84 | - if ($this->matchReference($referenceText)) { |
|
| 85 | - $reference = new Reference($referenceText); |
|
| 86 | - $this->fetchReference($reference); |
|
| 87 | - return $reference; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - private function fetchReference(Reference $reference): void { |
|
| 94 | - try { |
|
| 95 | - $user = $this->userSession->getUser(); |
|
| 96 | - if ($user) { |
|
| 97 | - $this->limiter->registerUserRequest('opengraph', 10, 120, $user); |
|
| 98 | - } else { |
|
| 99 | - $this->limiter->registerAnonRequest('opengraph', 10, 120, $this->request->getRemoteAddress()); |
|
| 100 | - } |
|
| 101 | - } catch (RateLimitExceededException $e) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $client = $this->clientService->newClient(); |
|
| 106 | - try { |
|
| 107 | - $response = $client->get($reference->getId(), [ 'timeout' => 10 ]); |
|
| 108 | - } catch (\Exception $e) { |
|
| 109 | - $this->logger->debug('Failed to fetch link for obtaining open graph data', ['exception' => $e]); |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $responseBody = (string)$response->getBody(); |
|
| 114 | - |
|
| 115 | - // OpenGraph handling |
|
| 116 | - $consumer = new Consumer(); |
|
| 117 | - $consumer->useFallbackMode = true; |
|
| 118 | - $object = $consumer->loadHtml($responseBody); |
|
| 119 | - |
|
| 120 | - $reference->setUrl($reference->getId()); |
|
| 121 | - |
|
| 122 | - if ($object->title) { |
|
| 123 | - $reference->setTitle($object->title); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if ($object->description) { |
|
| 127 | - $reference->setDescription($object->description); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($object->images) { |
|
| 131 | - try { |
|
| 132 | - $appData = $this->appDataFactory->get('core'); |
|
| 133 | - try { |
|
| 134 | - $folder = $appData->getFolder('opengraph'); |
|
| 135 | - } catch (NotFoundException $e) { |
|
| 136 | - $folder = $appData->newFolder('opengraph'); |
|
| 137 | - } |
|
| 138 | - $response = $client->get($object->images[0]->url, [ 'timeout' => 10 ]); |
|
| 139 | - $contentType = $response->getHeader('Content-Type'); |
|
| 140 | - $contentLength = $response->getHeader('Content-Length'); |
|
| 141 | - |
|
| 142 | - if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) { |
|
| 143 | - $stream = Utils::streamFor($response->getBody()); |
|
| 144 | - $bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0); |
|
| 145 | - $reference->setImageContentType($contentType); |
|
| 146 | - $folder->newFile(md5($reference->getId()), $bodyStream->getContents()); |
|
| 147 | - $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())])); |
|
| 148 | - } |
|
| 149 | - } catch (\Throwable $e) { |
|
| 150 | - $this->logger->error('Failed to fetch and store the open graph image for ' . $reference->getId(), ['exception' => $e]); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function getCachePrefix(string $referenceId): string { |
|
| 156 | - return $referenceId; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - public function getCacheKey(string $referenceId): ?string { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 44 | + public const MAX_PREVIEW_SIZE = 1024 * 1024; |
|
| 45 | + |
|
| 46 | + public const ALLOWED_CONTENT_TYPES = [ |
|
| 47 | + 'image/png', |
|
| 48 | + 'image/jpg', |
|
| 49 | + 'image/jpeg', |
|
| 50 | + 'image/gif', |
|
| 51 | + 'image/svg+xml', |
|
| 52 | + 'image/webp' |
|
| 53 | + ]; |
|
| 54 | + |
|
| 55 | + private IClientService $clientService; |
|
| 56 | + private LoggerInterface $logger; |
|
| 57 | + private SystemConfig $systemConfig; |
|
| 58 | + private IAppDataFactory $appDataFactory; |
|
| 59 | + private IURLGenerator $urlGenerator; |
|
| 60 | + private Limiter $limiter; |
|
| 61 | + private IUserSession $userSession; |
|
| 62 | + private IRequest $request; |
|
| 63 | + |
|
| 64 | + public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator, Limiter $limiter, IUserSession $userSession, IRequest $request) { |
|
| 65 | + $this->clientService = $clientService; |
|
| 66 | + $this->logger = $logger; |
|
| 67 | + $this->systemConfig = $systemConfig; |
|
| 68 | + $this->appDataFactory = $appDataFactory; |
|
| 69 | + $this->urlGenerator = $urlGenerator; |
|
| 70 | + $this->limiter = $limiter; |
|
| 71 | + $this->userSession = $userSession; |
|
| 72 | + $this->request = $request; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function matchReference(string $referenceText): bool { |
|
| 76 | + if ($this->systemConfig->getValue('reference_opengraph', true) !== true) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return (bool)preg_match(IURLGenerator::URL_REGEX, $referenceText); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function resolveReference(string $referenceText): ?IReference { |
|
| 84 | + if ($this->matchReference($referenceText)) { |
|
| 85 | + $reference = new Reference($referenceText); |
|
| 86 | + $this->fetchReference($reference); |
|
| 87 | + return $reference; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + private function fetchReference(Reference $reference): void { |
|
| 94 | + try { |
|
| 95 | + $user = $this->userSession->getUser(); |
|
| 96 | + if ($user) { |
|
| 97 | + $this->limiter->registerUserRequest('opengraph', 10, 120, $user); |
|
| 98 | + } else { |
|
| 99 | + $this->limiter->registerAnonRequest('opengraph', 10, 120, $this->request->getRemoteAddress()); |
|
| 100 | + } |
|
| 101 | + } catch (RateLimitExceededException $e) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $client = $this->clientService->newClient(); |
|
| 106 | + try { |
|
| 107 | + $response = $client->get($reference->getId(), [ 'timeout' => 10 ]); |
|
| 108 | + } catch (\Exception $e) { |
|
| 109 | + $this->logger->debug('Failed to fetch link for obtaining open graph data', ['exception' => $e]); |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $responseBody = (string)$response->getBody(); |
|
| 114 | + |
|
| 115 | + // OpenGraph handling |
|
| 116 | + $consumer = new Consumer(); |
|
| 117 | + $consumer->useFallbackMode = true; |
|
| 118 | + $object = $consumer->loadHtml($responseBody); |
|
| 119 | + |
|
| 120 | + $reference->setUrl($reference->getId()); |
|
| 121 | + |
|
| 122 | + if ($object->title) { |
|
| 123 | + $reference->setTitle($object->title); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if ($object->description) { |
|
| 127 | + $reference->setDescription($object->description); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($object->images) { |
|
| 131 | + try { |
|
| 132 | + $appData = $this->appDataFactory->get('core'); |
|
| 133 | + try { |
|
| 134 | + $folder = $appData->getFolder('opengraph'); |
|
| 135 | + } catch (NotFoundException $e) { |
|
| 136 | + $folder = $appData->newFolder('opengraph'); |
|
| 137 | + } |
|
| 138 | + $response = $client->get($object->images[0]->url, [ 'timeout' => 10 ]); |
|
| 139 | + $contentType = $response->getHeader('Content-Type'); |
|
| 140 | + $contentLength = $response->getHeader('Content-Length'); |
|
| 141 | + |
|
| 142 | + if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) { |
|
| 143 | + $stream = Utils::streamFor($response->getBody()); |
|
| 144 | + $bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0); |
|
| 145 | + $reference->setImageContentType($contentType); |
|
| 146 | + $folder->newFile(md5($reference->getId()), $bodyStream->getContents()); |
|
| 147 | + $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())])); |
|
| 148 | + } |
|
| 149 | + } catch (\Throwable $e) { |
|
| 150 | + $this->logger->error('Failed to fetch and store the open graph image for ' . $reference->getId(), ['exception' => $e]); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function getCachePrefix(string $referenceId): string { |
|
| 156 | + return $referenceId; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + public function getCacheKey(string $referenceId): ?string { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | return false; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - return (bool)preg_match(IURLGenerator::URL_REGEX, $referenceText); |
|
| 80 | + return (bool) preg_match(IURLGenerator::URL_REGEX, $referenceText); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public function resolveReference(string $referenceText): ?IReference { |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $client = $this->clientService->newClient(); |
| 106 | 106 | try { |
| 107 | - $response = $client->get($reference->getId(), [ 'timeout' => 10 ]); |
|
| 107 | + $response = $client->get($reference->getId(), ['timeout' => 10]); |
|
| 108 | 108 | } catch (\Exception $e) { |
| 109 | 109 | $this->logger->debug('Failed to fetch link for obtaining open graph data', ['exception' => $e]); |
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $responseBody = (string)$response->getBody(); |
|
| 113 | + $responseBody = (string) $response->getBody(); |
|
| 114 | 114 | |
| 115 | 115 | // OpenGraph handling |
| 116 | 116 | $consumer = new Consumer(); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } catch (NotFoundException $e) { |
| 136 | 136 | $folder = $appData->newFolder('opengraph'); |
| 137 | 137 | } |
| 138 | - $response = $client->get($object->images[0]->url, [ 'timeout' => 10 ]); |
|
| 138 | + $response = $client->get($object->images[0]->url, ['timeout' => 10]); |
|
| 139 | 139 | $contentType = $response->getHeader('Content-Type'); |
| 140 | 140 | $contentLength = $response->getHeader('Content-Length'); |
| 141 | 141 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())])); |
| 148 | 148 | } |
| 149 | 149 | } catch (\Throwable $e) { |
| 150 | - $this->logger->error('Failed to fetch and store the open graph image for ' . $reference->getId(), ['exception' => $e]); |
|
| 150 | + $this->logger->error('Failed to fetch and store the open graph image for '.$reference->getId(), ['exception' => $e]); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -28,136 +28,136 @@ |
||
| 28 | 28 | use OCP\Collaboration\Reference\IReference; |
| 29 | 29 | |
| 30 | 30 | class Reference implements IReference { |
| 31 | - private string $reference; |
|
| 32 | - |
|
| 33 | - private bool $accessible = true; |
|
| 34 | - |
|
| 35 | - private ?string $title = null; |
|
| 36 | - private ?string $description = null; |
|
| 37 | - private ?string $imageUrl = null; |
|
| 38 | - private ?string $contentType = null; |
|
| 39 | - private ?string $url = null; |
|
| 40 | - |
|
| 41 | - private ?string $richObjectType = null; |
|
| 42 | - private ?array $richObject = null; |
|
| 43 | - |
|
| 44 | - public function __construct(string $reference) { |
|
| 45 | - $this->reference = $reference; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function getId(): string { |
|
| 49 | - return $this->reference; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function setAccessible(bool $accessible): void { |
|
| 53 | - $this->accessible = $accessible; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function getAccessible(): bool { |
|
| 57 | - return $this->accessible; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function setTitle(string $title): void { |
|
| 61 | - $this->title = $title; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function getTitle(): string { |
|
| 65 | - return $this->title ?? $this->reference; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function setDescription(?string $description): void { |
|
| 69 | - $this->description = $description; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function getDescription(): ?string { |
|
| 73 | - return $this->description; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function setImageUrl(?string $imageUrl): void { |
|
| 77 | - $this->imageUrl = $imageUrl; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function getImageUrl(): ?string { |
|
| 81 | - return $this->imageUrl; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function setImageContentType(?string $contentType): void { |
|
| 85 | - $this->contentType = $contentType; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function getImageContentType(): ?string { |
|
| 89 | - return $this->contentType; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function setUrl(?string $url): void { |
|
| 93 | - $this->url = $url; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function getUrl(): ?string { |
|
| 97 | - return $this->url; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function setRichObject(string $type, ?array $richObject): void { |
|
| 101 | - $this->richObjectType = $type; |
|
| 102 | - $this->richObject = $richObject; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function getRichObjectType(): string { |
|
| 106 | - if ($this->richObjectType === null) { |
|
| 107 | - return 'open-graph'; |
|
| 108 | - } |
|
| 109 | - return $this->richObjectType; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function getRichObject(): array { |
|
| 113 | - if ($this->richObject === null) { |
|
| 114 | - return $this->getOpenGraphObject(); |
|
| 115 | - } |
|
| 116 | - return $this->richObject; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getOpenGraphObject(): array { |
|
| 120 | - return [ |
|
| 121 | - 'id' => $this->getId(), |
|
| 122 | - 'name' => $this->getTitle(), |
|
| 123 | - 'description' => $this->getDescription(), |
|
| 124 | - 'thumb' => $this->getImageUrl(), |
|
| 125 | - 'link' => $this->getUrl() |
|
| 126 | - ]; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public static function toCache(IReference $reference): array { |
|
| 130 | - return [ |
|
| 131 | - 'id' => $reference->getId(), |
|
| 132 | - 'title' => $reference->getTitle(), |
|
| 133 | - 'imageUrl' => $reference->getImageUrl(), |
|
| 134 | - 'imageContentType' => $reference->getImageContentType(), |
|
| 135 | - 'description' => $reference->getDescription(), |
|
| 136 | - 'link' => $reference->getUrl(), |
|
| 137 | - 'accessible' => $reference->getAccessible(), |
|
| 138 | - 'richObjectType' => $reference->getRichObjectType(), |
|
| 139 | - 'richObject' => $reference->getRichObject(), |
|
| 140 | - ]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public static function fromCache(array $cache): IReference { |
|
| 144 | - $reference = new Reference($cache['id']); |
|
| 145 | - $reference->setTitle($cache['title']); |
|
| 146 | - $reference->setDescription($cache['description']); |
|
| 147 | - $reference->setImageUrl($cache['imageUrl']); |
|
| 148 | - $reference->setImageContentType($cache['imageContentType']); |
|
| 149 | - $reference->setUrl($cache['link']); |
|
| 150 | - $reference->setRichObject($cache['richObjectType'], $cache['richObject']); |
|
| 151 | - $reference->setAccessible($cache['accessible']); |
|
| 152 | - return $reference; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function jsonSerialize() { |
|
| 156 | - return [ |
|
| 157 | - 'richObjectType' => $this->getRichObjectType(), |
|
| 158 | - 'richObject' => $this->getRichObject(), |
|
| 159 | - 'openGraphObject' => $this->getOpenGraphObject(), |
|
| 160 | - 'accessible' => $this->accessible |
|
| 161 | - ]; |
|
| 162 | - } |
|
| 31 | + private string $reference; |
|
| 32 | + |
|
| 33 | + private bool $accessible = true; |
|
| 34 | + |
|
| 35 | + private ?string $title = null; |
|
| 36 | + private ?string $description = null; |
|
| 37 | + private ?string $imageUrl = null; |
|
| 38 | + private ?string $contentType = null; |
|
| 39 | + private ?string $url = null; |
|
| 40 | + |
|
| 41 | + private ?string $richObjectType = null; |
|
| 42 | + private ?array $richObject = null; |
|
| 43 | + |
|
| 44 | + public function __construct(string $reference) { |
|
| 45 | + $this->reference = $reference; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function getId(): string { |
|
| 49 | + return $this->reference; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function setAccessible(bool $accessible): void { |
|
| 53 | + $this->accessible = $accessible; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function getAccessible(): bool { |
|
| 57 | + return $this->accessible; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function setTitle(string $title): void { |
|
| 61 | + $this->title = $title; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function getTitle(): string { |
|
| 65 | + return $this->title ?? $this->reference; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function setDescription(?string $description): void { |
|
| 69 | + $this->description = $description; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function getDescription(): ?string { |
|
| 73 | + return $this->description; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function setImageUrl(?string $imageUrl): void { |
|
| 77 | + $this->imageUrl = $imageUrl; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function getImageUrl(): ?string { |
|
| 81 | + return $this->imageUrl; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function setImageContentType(?string $contentType): void { |
|
| 85 | + $this->contentType = $contentType; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function getImageContentType(): ?string { |
|
| 89 | + return $this->contentType; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function setUrl(?string $url): void { |
|
| 93 | + $this->url = $url; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function getUrl(): ?string { |
|
| 97 | + return $this->url; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function setRichObject(string $type, ?array $richObject): void { |
|
| 101 | + $this->richObjectType = $type; |
|
| 102 | + $this->richObject = $richObject; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function getRichObjectType(): string { |
|
| 106 | + if ($this->richObjectType === null) { |
|
| 107 | + return 'open-graph'; |
|
| 108 | + } |
|
| 109 | + return $this->richObjectType; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function getRichObject(): array { |
|
| 113 | + if ($this->richObject === null) { |
|
| 114 | + return $this->getOpenGraphObject(); |
|
| 115 | + } |
|
| 116 | + return $this->richObject; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getOpenGraphObject(): array { |
|
| 120 | + return [ |
|
| 121 | + 'id' => $this->getId(), |
|
| 122 | + 'name' => $this->getTitle(), |
|
| 123 | + 'description' => $this->getDescription(), |
|
| 124 | + 'thumb' => $this->getImageUrl(), |
|
| 125 | + 'link' => $this->getUrl() |
|
| 126 | + ]; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public static function toCache(IReference $reference): array { |
|
| 130 | + return [ |
|
| 131 | + 'id' => $reference->getId(), |
|
| 132 | + 'title' => $reference->getTitle(), |
|
| 133 | + 'imageUrl' => $reference->getImageUrl(), |
|
| 134 | + 'imageContentType' => $reference->getImageContentType(), |
|
| 135 | + 'description' => $reference->getDescription(), |
|
| 136 | + 'link' => $reference->getUrl(), |
|
| 137 | + 'accessible' => $reference->getAccessible(), |
|
| 138 | + 'richObjectType' => $reference->getRichObjectType(), |
|
| 139 | + 'richObject' => $reference->getRichObject(), |
|
| 140 | + ]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public static function fromCache(array $cache): IReference { |
|
| 144 | + $reference = new Reference($cache['id']); |
|
| 145 | + $reference->setTitle($cache['title']); |
|
| 146 | + $reference->setDescription($cache['description']); |
|
| 147 | + $reference->setImageUrl($cache['imageUrl']); |
|
| 148 | + $reference->setImageContentType($cache['imageContentType']); |
|
| 149 | + $reference->setUrl($cache['link']); |
|
| 150 | + $reference->setRichObject($cache['richObjectType'], $cache['richObject']); |
|
| 151 | + $reference->setAccessible($cache['accessible']); |
|
| 152 | + return $reference; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function jsonSerialize() { |
|
| 156 | + return [ |
|
| 157 | + 'richObjectType' => $this->getRichObjectType(), |
|
| 158 | + 'richObject' => $this->getRichObject(), |
|
| 159 | + 'openGraphObject' => $this->getOpenGraphObject(), |
|
| 160 | + 'accessible' => $this->accessible |
|
| 161 | + ]; |
|
| 162 | + } |
|
| 163 | 163 | } |
@@ -32,30 +32,30 @@ |
||
| 32 | 32 | use OCP\Share\Events\ShareDeletedEvent; |
| 33 | 33 | |
| 34 | 34 | class FileReferenceEventListener implements \OCP\EventDispatcher\IEventListener { |
| 35 | - private IReferenceManager $manager; |
|
| 35 | + private IReferenceManager $manager; |
|
| 36 | 36 | |
| 37 | - public function __construct(IReferenceManager $manager) { |
|
| 38 | - $this->manager = $manager; |
|
| 39 | - } |
|
| 37 | + public function __construct(IReferenceManager $manager) { |
|
| 38 | + $this->manager = $manager; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public static function register(IEventDispatcher $eventDispatcher): void { |
|
| 42 | - $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileReferenceEventListener::class); |
|
| 43 | - $eventDispatcher->addServiceListener(ShareDeletedEvent::class, FileReferenceEventListener::class); |
|
| 44 | - $eventDispatcher->addServiceListener(ShareCreatedEvent::class, FileReferenceEventListener::class); |
|
| 45 | - } |
|
| 41 | + public static function register(IEventDispatcher $eventDispatcher): void { |
|
| 42 | + $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileReferenceEventListener::class); |
|
| 43 | + $eventDispatcher->addServiceListener(ShareDeletedEvent::class, FileReferenceEventListener::class); |
|
| 44 | + $eventDispatcher->addServiceListener(ShareCreatedEvent::class, FileReferenceEventListener::class); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @inheritDoc |
|
| 49 | - */ |
|
| 50 | - public function handle(Event $event): void { |
|
| 51 | - if ($event instanceof NodeDeletedEvent) { |
|
| 52 | - $this->manager->invalidateCache((string)$event->getNode()->getId()); |
|
| 53 | - } |
|
| 54 | - if ($event instanceof ShareDeletedEvent) { |
|
| 55 | - $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 56 | - } |
|
| 57 | - if ($event instanceof ShareCreatedEvent) { |
|
| 58 | - $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 59 | - } |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * @inheritDoc |
|
| 49 | + */ |
|
| 50 | + public function handle(Event $event): void { |
|
| 51 | + if ($event instanceof NodeDeletedEvent) { |
|
| 52 | + $this->manager->invalidateCache((string)$event->getNode()->getId()); |
|
| 53 | + } |
|
| 54 | + if ($event instanceof ShareDeletedEvent) { |
|
| 55 | + $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 56 | + } |
|
| 57 | + if ($event instanceof ShareCreatedEvent) { |
|
| 58 | + $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -49,13 +49,13 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | public function handle(Event $event): void { |
| 51 | 51 | if ($event instanceof NodeDeletedEvent) { |
| 52 | - $this->manager->invalidateCache((string)$event->getNode()->getId()); |
|
| 52 | + $this->manager->invalidateCache((string) $event->getNode()->getId()); |
|
| 53 | 53 | } |
| 54 | 54 | if ($event instanceof ShareDeletedEvent) { |
| 55 | - $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 55 | + $this->manager->invalidateCache((string) $event->getShare()->getNodeId()); |
|
| 56 | 56 | } |
| 57 | 57 | if ($event instanceof ShareCreatedEvent) { |
| 58 | - $this->manager->invalidateCache((string)$event->getShare()->getNodeId()); |
|
| 58 | + $this->manager->invalidateCache((string) $event->getShare()->getNodeId()); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -38,116 +38,116 @@ |
||
| 38 | 38 | use OCP\IUserSession; |
| 39 | 39 | |
| 40 | 40 | class FileReferenceProvider implements IReferenceProvider { |
| 41 | - private IURLGenerator $urlGenerator; |
|
| 42 | - private IRootFolder $rootFolder; |
|
| 43 | - private ?string $userId; |
|
| 44 | - private IPreview $previewManager; |
|
| 45 | - |
|
| 46 | - public function __construct(IURLGenerator $urlGenerator, IRootFolder $rootFolder, IUserSession $userSession, IPreview $previewManager) { |
|
| 47 | - $this->urlGenerator = $urlGenerator; |
|
| 48 | - $this->rootFolder = $rootFolder; |
|
| 49 | - $this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null; |
|
| 50 | - $this->previewManager = $previewManager; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function matchReference(string $referenceText): bool { |
|
| 54 | - return $this->getFilesAppLinkId($referenceText) !== null; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - private function getFilesAppLinkId(string $referenceText): ?int { |
|
| 58 | - $start = $this->urlGenerator->getAbsoluteURL('/apps/files'); |
|
| 59 | - $startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/files'); |
|
| 60 | - |
|
| 61 | - $fileId = null; |
|
| 62 | - |
|
| 63 | - if (mb_strpos($referenceText, $start) === 0) { |
|
| 64 | - $parts = parse_url($referenceText); |
|
| 65 | - parse_str($parts['query'], $query); |
|
| 66 | - $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 67 | - $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (mb_strpos($referenceText, $startIndex) === 0) { |
|
| 71 | - $parts = parse_url($referenceText); |
|
| 72 | - parse_str($parts['query'], $query); |
|
| 73 | - $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 74 | - $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - if (mb_strpos($referenceText, $this->urlGenerator->getAbsoluteURL('/index.php/f/')) === 0) { |
|
| 78 | - $fileId = str_replace($this->urlGenerator->getAbsoluteURL('/index.php/f/'), '', $referenceText); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (mb_strpos($referenceText, $this->urlGenerator->getAbsoluteURL('/f/')) === 0) { |
|
| 82 | - $fileId = str_replace($this->urlGenerator->getAbsoluteURL('/f/'), '', $referenceText); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return $fileId !== null ? (int)$fileId : null; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function resolveReference(string $referenceText): ?IReference { |
|
| 89 | - if ($this->matchReference($referenceText)) { |
|
| 90 | - $reference = new Reference($referenceText); |
|
| 91 | - try { |
|
| 92 | - $this->fetchReference($reference); |
|
| 93 | - } catch (NotFoundException $e) { |
|
| 94 | - $reference->setRichObject('file', null); |
|
| 95 | - $reference->setAccessible(false); |
|
| 96 | - } |
|
| 97 | - return $reference; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @throws NotFoundException |
|
| 105 | - */ |
|
| 106 | - private function fetchReference(Reference $reference): void { |
|
| 107 | - if ($this->userId === null) { |
|
| 108 | - throw new NotFoundException(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $fileId = $this->getFilesAppLinkId($reference->getId()); |
|
| 112 | - if ($fileId === null) { |
|
| 113 | - throw new NotFoundException(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - try { |
|
| 117 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 118 | - $files = $userFolder->getById($fileId); |
|
| 119 | - |
|
| 120 | - if (empty($files)) { |
|
| 121 | - throw new NotFoundException(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** @var Node $file */ |
|
| 125 | - $file = array_shift($files); |
|
| 126 | - |
|
| 127 | - $reference->setTitle($file->getName()); |
|
| 128 | - $reference->setDescription($file->getMimetype()); |
|
| 129 | - $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId)); |
|
| 130 | - $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId])); |
|
| 131 | - |
|
| 132 | - $reference->setRichObject('file', [ |
|
| 133 | - 'id' => $file->getId(), |
|
| 134 | - 'name' => $file->getName(), |
|
| 135 | - 'size' => $file->getSize(), |
|
| 136 | - 'path' => $file->getPath(), |
|
| 137 | - 'link' => $reference->getUrl(), |
|
| 138 | - 'mimetype' => $file->getMimetype(), |
|
| 139 | - 'preview-available' => $this->previewManager->isAvailable($file) |
|
| 140 | - ]); |
|
| 141 | - } catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) { |
|
| 142 | - throw new NotFoundException(); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function getCachePrefix(string $referenceId): string { |
|
| 147 | - return (string)$this->getFilesAppLinkId($referenceId); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function getCacheKey(string $referenceId): ?string { |
|
| 151 | - return $this->userId ?? ''; |
|
| 152 | - } |
|
| 41 | + private IURLGenerator $urlGenerator; |
|
| 42 | + private IRootFolder $rootFolder; |
|
| 43 | + private ?string $userId; |
|
| 44 | + private IPreview $previewManager; |
|
| 45 | + |
|
| 46 | + public function __construct(IURLGenerator $urlGenerator, IRootFolder $rootFolder, IUserSession $userSession, IPreview $previewManager) { |
|
| 47 | + $this->urlGenerator = $urlGenerator; |
|
| 48 | + $this->rootFolder = $rootFolder; |
|
| 49 | + $this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null; |
|
| 50 | + $this->previewManager = $previewManager; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function matchReference(string $referenceText): bool { |
|
| 54 | + return $this->getFilesAppLinkId($referenceText) !== null; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + private function getFilesAppLinkId(string $referenceText): ?int { |
|
| 58 | + $start = $this->urlGenerator->getAbsoluteURL('/apps/files'); |
|
| 59 | + $startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/files'); |
|
| 60 | + |
|
| 61 | + $fileId = null; |
|
| 62 | + |
|
| 63 | + if (mb_strpos($referenceText, $start) === 0) { |
|
| 64 | + $parts = parse_url($referenceText); |
|
| 65 | + parse_str($parts['query'], $query); |
|
| 66 | + $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 67 | + $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (mb_strpos($referenceText, $startIndex) === 0) { |
|
| 71 | + $parts = parse_url($referenceText); |
|
| 72 | + parse_str($parts['query'], $query); |
|
| 73 | + $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 74 | + $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + if (mb_strpos($referenceText, $this->urlGenerator->getAbsoluteURL('/index.php/f/')) === 0) { |
|
| 78 | + $fileId = str_replace($this->urlGenerator->getAbsoluteURL('/index.php/f/'), '', $referenceText); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (mb_strpos($referenceText, $this->urlGenerator->getAbsoluteURL('/f/')) === 0) { |
|
| 82 | + $fileId = str_replace($this->urlGenerator->getAbsoluteURL('/f/'), '', $referenceText); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return $fileId !== null ? (int)$fileId : null; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function resolveReference(string $referenceText): ?IReference { |
|
| 89 | + if ($this->matchReference($referenceText)) { |
|
| 90 | + $reference = new Reference($referenceText); |
|
| 91 | + try { |
|
| 92 | + $this->fetchReference($reference); |
|
| 93 | + } catch (NotFoundException $e) { |
|
| 94 | + $reference->setRichObject('file', null); |
|
| 95 | + $reference->setAccessible(false); |
|
| 96 | + } |
|
| 97 | + return $reference; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @throws NotFoundException |
|
| 105 | + */ |
|
| 106 | + private function fetchReference(Reference $reference): void { |
|
| 107 | + if ($this->userId === null) { |
|
| 108 | + throw new NotFoundException(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $fileId = $this->getFilesAppLinkId($reference->getId()); |
|
| 112 | + if ($fileId === null) { |
|
| 113 | + throw new NotFoundException(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + try { |
|
| 117 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 118 | + $files = $userFolder->getById($fileId); |
|
| 119 | + |
|
| 120 | + if (empty($files)) { |
|
| 121 | + throw new NotFoundException(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** @var Node $file */ |
|
| 125 | + $file = array_shift($files); |
|
| 126 | + |
|
| 127 | + $reference->setTitle($file->getName()); |
|
| 128 | + $reference->setDescription($file->getMimetype()); |
|
| 129 | + $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId)); |
|
| 130 | + $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId])); |
|
| 131 | + |
|
| 132 | + $reference->setRichObject('file', [ |
|
| 133 | + 'id' => $file->getId(), |
|
| 134 | + 'name' => $file->getName(), |
|
| 135 | + 'size' => $file->getSize(), |
|
| 136 | + 'path' => $file->getPath(), |
|
| 137 | + 'link' => $reference->getUrl(), |
|
| 138 | + 'mimetype' => $file->getMimetype(), |
|
| 139 | + 'preview-available' => $this->previewManager->isAvailable($file) |
|
| 140 | + ]); |
|
| 141 | + } catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) { |
|
| 142 | + throw new NotFoundException(); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function getCachePrefix(string $referenceId): string { |
|
| 147 | + return (string)$this->getFilesAppLinkId($referenceId); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function getCacheKey(string $referenceId): ?string { |
|
| 151 | + return $this->userId ?? ''; |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | if (mb_strpos($referenceText, $start) === 0) { |
| 64 | 64 | $parts = parse_url($referenceText); |
| 65 | 65 | parse_str($parts['query'], $query); |
| 66 | - $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 67 | - $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 66 | + $fileId = isset($query['fileid']) ? (int) $query['fileid'] : $fileId; |
|
| 67 | + $fileId = isset($query['openfile']) ? (int) $query['openfile'] : $fileId; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (mb_strpos($referenceText, $startIndex) === 0) { |
| 71 | 71 | $parts = parse_url($referenceText); |
| 72 | 72 | parse_str($parts['query'], $query); |
| 73 | - $fileId = isset($query['fileid']) ? (int)$query['fileid'] : $fileId; |
|
| 74 | - $fileId = isset($query['openfile']) ? (int)$query['openfile'] : $fileId; |
|
| 73 | + $fileId = isset($query['fileid']) ? (int) $query['fileid'] : $fileId; |
|
| 74 | + $fileId = isset($query['openfile']) ? (int) $query['openfile'] : $fileId; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | if (mb_strpos($referenceText, $this->urlGenerator->getAbsoluteURL('/index.php/f/')) === 0) { |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $fileId = str_replace($this->urlGenerator->getAbsoluteURL('/f/'), '', $referenceText); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - return $fileId !== null ? (int)$fileId : null; |
|
| 85 | + return $fileId !== null ? (int) $fileId : null; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | public function resolveReference(string $referenceText): ?IReference { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | $reference->setTitle($file->getName()); |
| 128 | 128 | $reference->setDescription($file->getMimetype()); |
| 129 | - $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId)); |
|
| 129 | + $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/'.$fileId)); |
|
| 130 | 130 | $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId])); |
| 131 | 131 | |
| 132 | 132 | $reference->setRichObject('file', [ |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | 'mimetype' => $file->getMimetype(), |
| 139 | 139 | 'preview-available' => $this->previewManager->isAvailable($file) |
| 140 | 140 | ]); |
| 141 | - } catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) { |
|
| 141 | + } catch (InvalidPathException | NotFoundException | NotPermittedException | NoUserException $e) { |
|
| 142 | 142 | throw new NotFoundException(); |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | public function getCachePrefix(string $referenceId): string { |
| 147 | - return (string)$this->getFilesAppLinkId($referenceId); |
|
| 147 | + return (string) $this->getFilesAppLinkId($referenceId); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | public function getCacheKey(string $referenceId): ?string { |