]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/ParseUrl.php
Decouple conversation creation from rendering
[friendica.git] / src / Module / ParseUrl.php
index 8e72c4fa78160762408a3885bbc101f617007abe..e2d75ee8447fd70e2c561a4c5f5a021d26a78541 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module;
 
+use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Hook;
-use Friendica\Core\Session;
+use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Util;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 class ParseUrl extends BaseModule
 {
-       public static function rawContent(array $parameters = [])
+       /** @var IHandleUserSessions */
+       protected $userSession;
+
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->userSession = $userSession;
+       }
+
+       protected function rawContent(array $request = [])
        {
-               if (!Session::isAuthenticated()) {
+               if (!$this->userSession->isAuthenticated()) {
                        throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
@@ -88,16 +102,14 @@ class ParseUrl extends BaseModule
                        if ($format == 'json') {
                                System::jsonExit($arr['text']);
                        } else {
-                               echo $arr['text'];
-                               exit();
+                               System::httpExit($arr['text']);
                        }
                }
 
                if ($format == 'json') {
                        $siteinfo = Util\ParseUrl::getSiteinfoCached($url);
 
-                       if (empty($siteinfo['title']) && empty($siteinfo['text']) && empty($siteinfo['image'])
-                               && in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
+                       if (in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
                                switch ($siteinfo['type']) {
                                        case 'video':
                                                $content_type = 'video';
@@ -123,8 +135,7 @@ class ParseUrl extends BaseModule
 
                        System::jsonExit($ret);
                } else {
-                       echo BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? '');
-                       exit();
+                       System::httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? ''));
                }
        }
 }