]> git.mxchange.org Git - friendica.git/blob - src/Module/Calendar/Show.php
Adhere feedback
[friendica.git] / src / Module / Calendar / Show.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Calendar;
23
24 use Friendica\App;
25 use Friendica\BaseModule;
26 use Friendica\Content\Feature;
27 use Friendica\Content\Nav;
28 use Friendica\Content\Widget;
29 use Friendica\Core\L10n;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session\Capability\IHandleUserSessions;
32 use Friendica\Core\Theme;
33 use Friendica\Model\Event;
34 use Friendica\Model\Profile;
35 use Friendica\Model\User;
36 use Friendica\Module\BaseProfile;
37 use Friendica\Module\Response;
38 use Friendica\Module\Security\Login;
39 use Friendica\Network\HTTPException;
40 use Friendica\Navigation\SystemMessages;
41 use Friendica\Util\Profiler;
42 use Psr\Log\LoggerInterface;
43
44 class Show extends BaseModule
45 {
46         /** @var IHandleUserSessions */
47         protected $session;
48         /** @var SystemMessages */
49         protected $sysMessages;
50         /** @var App\Page */
51         protected $page;
52         /** @var App */
53         protected $app;
54
55         public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, App\Page $page, App $app, array $server, array $parameters = [])
56         {
57                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
58
59                 $this->session     = $session;
60                 $this->sysMessages = $sysMessages;
61                 $this->page        = $page;
62                 $this->app         = $app;
63         }
64
65         protected function content(array $request = []): string
66         {
67                 $nickname = $this->parameters['nickname'] ?? $this->session->getLocalUserNickname();
68                 if (!$nickname) {
69                         throw new HTTPException\UnauthorizedException();
70                 }
71
72                 $owner = Profile::load($this->app, $nickname, false);
73                 if (!$owner || $owner['account_expired'] || $owner['account_removed']) {
74                         throw new HTTPException\NotFoundException($this->t('User not found.'));
75                 }
76
77                 if (!$this->session->isAuthenticated() && $owner['hidewall']) {
78                         $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
79                 }
80
81                 if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) {
82                         $this->sysMessages->addNotice($this->t('Permission denied.'));
83                         return Login::form();
84                 }
85
86                 // get the translation strings for the calendar
87                 $i18n = Event::getStrings();
88
89                 $this->page->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
90                 $this->page->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
91                 $this->page->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
92                 $this->page->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
93
94                 $is_owner = $nickname == $this->app->getLoggedInUserNickname();
95
96                 $htpl = Renderer::getMarkupTemplate('calendar/calendar_head.tpl');
97                 $this->page['htmlhead'] .= Renderer::replaceMacros($htpl, [
98                         '$calendar_api' => 'calendar/api/get' . ($is_owner ? '' : '/' . $nickname),
99                         '$event_api'    => 'calendar/event/show' . ($is_owner ? '' : '/' . $nickname),
100                         '$modparams'    => 2,
101                         '$i18n'         => $i18n,
102                 ]);
103
104                 Nav::setSelected($is_owner ? 'home' : 'calendar');
105
106                 if ($is_owner) {
107                         // Removing the vCard added by Profile::load for owners
108                         $this->page['aside'] = '';
109                 }
110
111                 $this->page['aside'] .= Widget\CalendarExport::getHTML($owner['uid']);
112
113                 $tabs = BaseProfile::getTabsHTML('calendar', $is_owner, $nickname, !$is_owner && $owner['hide-friends']);
114
115                 // ACL blocks are loaded in modals in frio
116                 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
117                 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
118                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
119                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
120
121                 $tpl = Renderer::getMarkupTemplate("calendar/calendar.tpl");
122                 $o   = Renderer::replaceMacros($tpl, [
123                         '$tabs'      => $tabs,
124                         '$title'     => $this->t('Events'),
125                         '$view'      => $this->t('View'),
126                         '$new_event' => ['calendar/event/new', $this->t('Create New Event'), '', ''],
127
128                         '$today' => $this->t('today'),
129                         '$month' => $this->t('month'),
130                         '$week'  => $this->t('week'),
131                         '$day'   => $this->t('day'),
132                         '$list'  => $this->t('list'),
133                 ]);
134
135                 return $o;
136         }
137 }