]> _ Git - fluidbook-toolbox.git/commitdiff
#7825 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 7 Nov 2025 16:06:07 +0000 (17:06 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 7 Nov 2025 16:06:07 +0000 (17:06 +0100)
app/Models/FluidbookAuditLink.php
composer.json

index c47da3376870a4de673b47145c83e581a914145e..c73ff82f8e0552495529be182b76cedca511c6ce 100644 (file)
@@ -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.";
         }
     }
 }
index 8144b0998baedb630aa426bb1cafc7dcf752bed3..9ce5cbefacbe9bf22d9adf40bd408a347de7c9db 100644 (file)
@@ -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",