]> git.mxchange.org Git - friendica.git/blobdiff - mod/cal.php
Return the actor, not the array
[friendica.git] / mod / cal.php
index e6570018b7cb64aa8fcc972c5ff6b21b3992a2df..3f249da0aca21c457146fd4243eebc669ea06430 100644 (file)
@@ -1,6 +1,22 @@
 <?php
 /**
- * @file mod/cal.php
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  * The calendar module
  *
  * This calendar is for profile visitors and contains only the events
  */
 
 use Friendica\App;
-use Friendica\Content\Feature;
 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\Contact;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
+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()) {
-               throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
+               throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
        }
 
-       if ($a->argc < 2) {
-               throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
+       if (DI::args()->getArgc() < 2) {
+               throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
        }
 
        Nav::setSelected('events');
 
-       $nick = $a->argv[1];
-       $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
-       if (!DBA::isResult($user)) {
-               throw new \Friendica\Network\HTTPException\NotFoundException();
-       }
-
-       $a->data['user'] = $user;
-       $a->profile_uid = $user['uid'];
-
        // if it's a json request abort here becaus we don't
        // need the widget data
-       if (!empty($a->argv[2]) && ($a->argv[2] === 'json')) {
+       if (!empty(DI::args()->getArgv()[2]) && (DI::args()->getArgv()[2] === 'json')) {
                return;
        }
 
-       $profile = Profile::getByNickname($nick, $a->profile_uid);
-
-       $account_type = Contact::getAccountType($profile);
-
-       $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
-
-       $vcard_widget = Renderer::replaceMacros($tpl, [
-               '$name' => $profile['name'],
-               '$photo' => $profile['photo'],
-               '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
-               '$account_type' => $account_type,
-               '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
-       ]);
-
-       $cal_widget = Widget\CalendarExport::getHTML();
+       $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
+       if (empty($owner)) {
+               throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
+       }
 
        if (empty(DI::page()['aside'])) {
                DI::page()['aside'] = '';
        }
 
-       DI::page()['aside'] .= $vcard_widget;
-       DI::page()['aside'] .= $cal_widget;
+       DI::page()['aside'] .= Widget\VCard::getHTML($owner);
+       DI::page()['aside'] .= Widget\CalendarExport::getHTML($owner['uid']);
 
        return;
 }
 
 function cal_content(App $a)
 {
+       $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
+       if (empty($owner)) {
+               throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
+       }
+
        Nav::setSelected('events');
 
        // get the translation strings for the callendar
        $i18n = Event::getStrings();
 
+       DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
+       DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
+       DI::page()->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
+       DI::page()->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
+
        $htpl = Renderer::getMarkupTemplate('event_head.tpl');
        DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [
-               '$module_url' => '/cal/' . $a->data['user']['nickname'],
+               '$module_url' => '/cal/' . $owner['nickname'],
                '$modparams' => 2,
                '$i18n' => $i18n,
        ]);
@@ -95,23 +103,23 @@ function cal_content(App $a)
        $ignored = (!empty($_REQUEST['ignored']) ? intval($_REQUEST['ignored']) : 0);
 
        $format = 'ical';
-       if ($a->argc == 4 && $a->argv[2] == 'export') {
+       if (DI::args()->getArgc() == 4 && DI::args()->getArgv()[2] == 'export') {
                $mode = 'export';
-               $format = $a->argv[3];
+               $format = DI::args()->getArgv()[3];
        }
 
        // Setup permissions structures
-       $owner_uid = intval($a->data['user']['uid']);
-       $nick = $a->data['user']['nickname'];
+       $owner_uid = intval($owner['uid']);
+       $nick = $owner['nickname'];
 
-       $contact_id = Session::getRemoteContactID($a->profile['uid']);
+       $contact_id = Session::getRemoteContactID($owner['uid']);
 
-       $remote_contact = $contact_id && DBA::exists('contact', ['id' => $contact_id, 'uid' => $a->profile['uid']]);
+       $remote_contact = $contact_id && DBA::exists('contact', ['id' => $contact_id, 'uid' => $owner['uid']]);
 
-       $is_owner = local_user() == $a->profile['uid'];
+       $is_owner = local_user() == $owner['uid'];
 
-       if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
-               notice(DI::l10n()->t('Access to this profile has been restricted.') . EOL);
+       if ($owner['hidewall'] && !$is_owner && !$remote_contact) {
+               notice(DI::l10n()->t('Access to this profile has been restricted.'));
                return;
        }
 
@@ -121,7 +129,7 @@ function cal_content(App $a)
        $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
 
        // get the tab navigation bar
-       $tabs = Profile::getTabs($a, 'cal', false, $a->data['user']['nickname']);
+       $tabs = BaseProfile::getTabsHTML($a, 'cal', false, $owner['nickname'], $owner['hide-friends']);
 
        // The view mode part is similiar to /mod/events.php
        if ($mode == 'view') {
@@ -166,7 +174,7 @@ function cal_content(App $a)
                $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
 
 
-               if (!empty($a->argv[2]) && ($a->argv[2] === 'json')) {
+               if (!empty(DI::args()->getArgv()[2]) && (DI::args()->getArgv()[2] === 'json')) {
                        if (!empty($_GET['start'])) {
                                $start = $_GET['start'];
                        }
@@ -179,16 +187,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,
                ];
 
@@ -204,7 +207,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;
                                }
@@ -214,20 +217,15 @@ function cal_content(App $a)
                // transform the event in a usable array
                $events = Event::prepareListForTemplate($r);
 
-               if (!empty($a->argv[2]) && ($a->argv[2] === 'json')) {
-                       echo json_encode($events);
-                       exit();
+               if (!empty(DI::args()->getArgv()[2]) && (DI::args()->getArgv()[2] === 'json')) {
+                       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
@@ -256,8 +254,7 @@ function cal_content(App $a)
                ]);
 
                if (!empty($_GET['id'])) {
-                       echo $o;
-                       exit();
+                       System::httpExit($o);
                }
 
                return $o;
@@ -269,13 +266,6 @@ function cal_content(App $a)
                        return;
                }
 
-               // Test permissions
-               // Respect the export feature setting for all other /cal pages if it's not the own profile
-               if ((local_user() !== $owner_uid) && !Feature::isEnabled($owner_uid, "export_calendar")) {
-                       notice(DI::l10n()->t('Permission denied.') . EOL);
-                       DI::baseUrl()->redirect('cal/' . $nick);
-               }
-
                // Get the export data by uid
                $evexport = Event::exportListByUserId($owner_uid, $format);
 
@@ -299,10 +289,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;