]> git.mxchange.org Git - friendica.git/blobdiff - mod/cal.php
Fix missing/wrong IHandleUserSessions usages
[friendica.git] / mod / cal.php
index ac12d69b914c8e122bc50d1ba3eb2b750983ffab..4c22232d279f9c526b191fb6553c890f80b0da17 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -27,20 +27,21 @@ use Friendica\App;
 use Friendica\Content\Nav;
 use Friendica\Content\Widget;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
+use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
 
 function cal_init(App $a)
 {
-       if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
+       if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
                throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
        }
 
@@ -110,14 +111,14 @@ function cal_content(App $a)
        $owner_uid = intval($owner['uid']);
        $nick = $owner['nickname'];
 
-       $contact_id = Session::getRemoteContactID($owner['uid']);
+       $contact_id = DI::userSession()->getRemoteContactID($owner['uid']);
 
        $remote_contact = $contact_id && DBA::exists('contact', ['id' => $contact_id, 'uid' => $owner['uid']]);
 
-       $is_owner = local_user() == $owner['uid'];
+       $is_owner = DI::userSession()->getLocalUserId() == $owner['uid'];
 
        if ($owner['hidewall'] && !$is_owner && !$remote_contact) {
-               notice(DI::l10n()->t('Access to this profile has been restricted.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Access to this profile has been restricted.'));
                return;
        }
 
@@ -185,16 +186,11 @@ function cal_content(App $a)
                $start = DateTimeFormat::utc($start);
                $finish = DateTimeFormat::utc($finish);
 
-               $adjust_start = DateTimeFormat::local($start);
-               $adjust_finish = DateTimeFormat::local($finish);
-
                // put the event parametes in an array so we can better transmit them
                $event_params = [
                        'event_id'      => intval($_GET['id'] ?? 0),
                        'start'         => $start,
                        'finish'        => $finish,
-                       'adjust_start'  => $adjust_start,
-                       'adjust_finish' => $adjust_finish,
                        'ignore'        => $ignored,
                ];
 
@@ -210,7 +206,7 @@ function cal_content(App $a)
                if (DBA::isResult($r)) {
                        $r = Event::sortByDate($r);
                        foreach ($r as $rr) {
-                               $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
+                               $j = DateTimeFormat::local($rr['start'], 'j');
                                if (empty($links[$j])) {
                                        $links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
                                }
@@ -221,19 +217,14 @@ function cal_content(App $a)
                $events = Event::prepareListForTemplate($r);
 
                if (!empty(DI::args()->getArgv()[2]) && (DI::args()->getArgv()[2] === 'json')) {
-                       echo json_encode($events);
-                       exit();
+                       System::jsonExit($events);
                }
 
                // links: array('href', 'text', 'extra css classes', 'title')
                if (!empty($_GET['id'])) {
                        $tpl = Renderer::getMarkupTemplate("event.tpl");
                } else {
-//                     if (DI::config()->get('experimentals','new_calendar')==1){
                        $tpl = Renderer::getMarkupTemplate("events_js.tpl");
-//                     } else {
-//                             $tpl = Renderer::getMarkupTemplate("events.tpl");
-//                     }
                }
 
                // Get rid of dashes in key names, Smarty3 can't handle them
@@ -262,8 +253,7 @@ function cal_content(App $a)
                ]);
 
                if (!empty($_GET['id'])) {
-                       echo $o;
-                       exit();
+                       System::httpExit($o);
                }
 
                return $o;
@@ -271,7 +261,7 @@ function cal_content(App $a)
 
        if ($mode == 'export') {
                if (!$owner_uid) {
-                       notice(DI::l10n()->t('User not found'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('User not found'));
                        return;
                }
 
@@ -280,14 +270,14 @@ function cal_content(App $a)
 
                if (!$evexport["success"]) {
                        if ($evexport["content"]) {
-                               notice(DI::l10n()->t('This calendar format is not supported'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('This calendar format is not supported'));
                        } else {
-                               notice(DI::l10n()->t('No exportable data found'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('No exportable data found'));
                        }
 
                        // If it the own calendar return to the events page
                        // otherwise to the profile calendar page
-                       if (local_user() === $owner_uid) {
+                       if (DI::userSession()->getLocalUserId() === $owner_uid) {
                                $return_path = "events";
                        } else {
                                $return_path = "cal/" . $nick;
@@ -298,10 +288,8 @@ function cal_content(App $a)
 
                // If nothing went wrong we can echo the export content
                if ($evexport["success"]) {
-                       header('Content-type: text/calendar');
                        header('content-disposition: attachment; filename="' . DI::l10n()->t('calendar') . '-' . $nick . '.' . $evexport["extension"] . '"');
-                       echo $evexport["content"];
-                       exit();
+                       System::httpExit($evexport["content"], Response::TYPE_BLANK, 'text/calendar');
                }
 
                return;