diff --git a/src/Service/UWService.php b/src/Service/UWService.php index 4f2aa82de084cfd701f8b3e1fc960dbcdf751720..7e6a4bb38fce10e58eba634b281f9eb403a22ef5 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -594,4 +594,20 @@ class UWService implements UWServiceInterface { return $list; } + /** + * {@inheritDoc} + */ + public function validExternalUrl(string $url): bool { + + // Get the headers of the URL. + $headers = @get_headers($url); + + // Use condition to check if there is no URL. + if ($headers && strpos($headers[0], '404')) { + return FALSE; + } + + return TRUE; + } + } diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 1311d7f9ed1bd64d28db4df41ac923db1349f19d..b8eaee2752cf3342a0740c06586e7c97ddd63106 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -211,4 +211,15 @@ interface UWServiceInterface { */ public function getContentTypeUsage(array $content_types, bool $show_null_content_types): array; + /** + * Function to check if an external url is valid. + * + * @param string $url + * The URL to be checked. + * + * @return bool + * Whether url is valid or not. + */ + public function validExternalUrl(string $url): bool; + }