From 3f0dcbe188928527f57ac3c93f83e1bffa234570 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 7 Nov 2025 17:06:07 +0100 Subject: [PATCH] #7825 @0.25 --- app/Models/FluidbookAuditLink.php | 50 +++++++++++++++---------------- composer.json | 3 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/Models/FluidbookAuditLink.php b/app/Models/FluidbookAuditLink.php index c47da3376..c73ff82f8 100644 --- a/app/Models/FluidbookAuditLink.php +++ b/app/Models/FluidbookAuditLink.php @@ -26,36 +26,32 @@ class FluidbookAuditLink extends ToolboxModel { parent::setFields(); - $this->addField('fluidbook_id', Integer::class, '',[]); - $this->addField('page', Integer::class, '',[]); - $this->addField('link_id', Text::class, '',[]); - $this->addField('error_code', Text::class, '',[]); - $this->addField('first_time_error', Text::class, '',['default' => '']); - $this->addField('last_date_test', Text::class, '',['default' => '']); - $this->addField('url', Text::class, '',[]); - $this->addField('new_url', Text::class, '',['default' => '']); - $this->addField('redirection_code', Text::class, '',[]); - $this->addField('final_code_url', Text::class, '',['default' => '']); - $this->addField('final_target', Text::class, '',['default' => '']); + $this->addField('fluidbook_id', Integer::class, '', []); + $this->addField('page', Integer::class, '', []); + $this->addField('link_id', Text::class, '', []); + $this->addField('error_code', Text::class, '', []); + $this->addField('first_time_error', Text::class, '', ['default' => '']); + $this->addField('last_date_test', Text::class, '', ['default' => '']); + $this->addField('url', Text::class, '', []); + $this->addField('new_url', Text::class, '', ['default' => '']); + $this->addField('redirection_code', Text::class, '', []); + $this->addField('final_code_url', Text::class, '', ['default' => '']); + $this->addField('final_target', Text::class, '', ['default' => '']); } - public static function youtubeVideoExist($videoID) { + public static function youtubeVideoExist($videoID) + { $headers = get_headers('https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=' . $videoID); - - if(is_array($headers) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$headers[0]) : false){ - // video exists - } else { - return false; - } - return true; + return (is_array($headers) && preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/', $headers[0])); } - public static function getHttpCode($url) { + public static function getHttpCode($url, $timeout = 30) + { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_NOBODY, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HEADER, true); @@ -68,13 +64,17 @@ class FluidbookAuditLink extends ToolboxModel return ['httpcode' => $httpcode, 'finalurl' => $finalUrl]; } - public static function getHttpCodeComment($httpcode) { + public static function getHttpCodeComment($httpcode) + { switch ($httpcode) { - case 301: echo " - Moved Permanently: the resource has a new permanent home — update your bookmarks or links."; break; - case 302: echo " - Found: tells the client to look at (browse to) another URL."; break; + case 301: + return " - Moved Permanently: the resource has a new permanent home — update your bookmarks or links."; + case 302: + return " - Found: tells the client to look at (browse to) another URL."; //case 307: //case 308: - case 400: echo " - Bad request: this and all future requests should be directed to the given URI."; break; + case 400: + return " - Bad request: this and all future requests should be directed to the given URI."; } } } diff --git a/composer.json b/composer.json index 8144b0998..9ce5cbefa 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,8 @@ "symfony/http-client": "^v6.4.0", "theafolayan/listmonk-laravel": "^1.3", "typesense/typesense-php": "^5.1", - "voku/simple_html_dom": "^4.8" + "voku/simple_html_dom": "^4.8", + "ext-curl": "*" }, "require-dev": { "spatie/laravel-ignition": "^2.9", -- 2.39.5