]> git.mxchange.org Git - friendica.git/commitdiff
Move "getUserAgent()" to "HTTPRequest" class
authornupplaPhil <admin+github@philipp.info>
Wed, 4 Mar 2020 21:26:38 +0000 (22:26 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 21 Jul 2020 07:04:58 +0000 (03:04 -0400)
src/App.php
src/Content/Text/BBCode.php
src/Network/HTTPRequest.php
src/Util/Network.php

index 9b6f6a5a296eea138749891e8b93c320caeeeee0..65ae3fe2f47389583dc0286733f1d4a2c528b990 100644 (file)
@@ -240,22 +240,6 @@ class App
                }
        }
 
-       /**
-        * Returns the current UserAgent as a String
-        *
-        * @return string the UserAgent as a String
-        * @throws HTTPException\InternalServerErrorException
-        */
-       public function getUserAgent()
-       {
-               return
-                       FRIENDICA_PLATFORM . " '" .
-                       FRIENDICA_CODENAME . "' " .
-                       FRIENDICA_VERSION . '-' .
-                       DB_UPDATE_VERSION . '; ' .
-                       $this->baseURL->get();
-       }
-
        /**
         * Returns the current theme name. May be overriden by the mobile theme name.
         *
index 9d9679c4940462ecb004c5f7059c49789a3e9b8e..036bc4a2706a4d39f12c6dff763eb4a0082b7e67 100644 (file)
@@ -1094,7 +1094,7 @@ class BBCode
                        $ch = @curl_init($match[1]);
                        @curl_setopt($ch, CURLOPT_NOBODY, true);
                        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-                       @curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
+                       @curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
                        @curl_exec($ch);
                        $curl_info = @curl_getinfo($ch);
 
@@ -1168,7 +1168,7 @@ class BBCode
                $ch = @curl_init($match[1]);
                @curl_setopt($ch, CURLOPT_NOBODY, true);
                @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-               @curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
+               @curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
                @curl_exec($ch);
                $curl_info = @curl_getinfo($ch);
 
index ac2d70cad27621bfd27fac65c2b4fd045b3e7d0b..1a0048b2a135d9e22e3e9668680873eb7823d396 100644 (file)
@@ -41,14 +41,14 @@ class HTTPRequest
        /** @var IConfig */
        private $config;
        /** @var string */
-       private $userAgent;
+       private $baseUrl;
 
-       public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App $a)
+       public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App\BaseURL $baseUrl)
        {
-               $this->logger    = $logger;
-               $this->profiler  = $profiler;
-               $this->config    = $config;
-               $this->userAgent = $a->getUserAgent();
+               $this->logger   = $logger;
+               $this->profiler = $profiler;
+               $this->config   = $config;
+               $this->baseUrl  = $baseUrl->get();
        }
 
        /**
@@ -232,7 +232,7 @@ class HTTPRequest
                $stamp1 = microtime(true);
 
                if (Network::isUrlBlocked($url)) {
-                       $this->logger->info('Domain is blocked.'. ['url' => $url]);
+                       $this->logger->info('Domain is blocked.' . ['url' => $url]);
                        return CurlResult::createErrorCurl($url);
                }
 
@@ -378,4 +378,19 @@ class HTTPRequest
                        $redirects
                );
        }
+
+       /**
+        * Returns the current UserAgent as a String
+        *
+        * @return string the UserAgent as a String
+        */
+       public function getUserAgent()
+       {
+               return
+                       FRIENDICA_PLATFORM . " '" .
+                       FRIENDICA_CODENAME . "' " .
+                       FRIENDICA_VERSION . '-' .
+                       DB_UPDATE_VERSION . '; ' .
+                       $this->baseUrl;
+       }
 }
index 888dc20a692e386946ea8b3ee87693570e2069df..a8b216b34bfe5233357cecdb25e7d0ff20a7ee59 100644 (file)
@@ -350,7 +350,7 @@ class Network
                curl_setopt($ch, CURLOPT_NOBODY, 1);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-               curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
+               curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
 
                curl_exec($ch);
                $curl_info = @curl_getinfo($ch);
@@ -394,7 +394,7 @@ class Network
                curl_setopt($ch, CURLOPT_NOBODY, 0);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-               curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
+               curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
 
                $body = curl_exec($ch);
                curl_close($ch);