]> git.mxchange.org Git - friendica.git/blob - src/Module/Calendar/Show.php
Update src/Module/Api/Friendica/Photoalbum/Index.php
[friendica.git] / src / Module / Calendar / Show.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\User;
35 use Friendica\Module\BaseProfile;
36 use Friendica\Module\Response;
37 use Friendica\Module\Security\Login;
38 use Friendica\Network\HTTPException;
39 use Friendica\Navigation\SystemMessages;
40 use Friendica\Util\Profiler;
41 use Psr\Log\LoggerInterface;
42
43 class Show extends BaseModule
44 {
45         /** @var IHandleUserSessions */
46         protected $session;
47         /** @var SystemMessages */
48         protected $sysMessages;
49         /** @var App\Page */
50         protected $page;
51         /** @var App */
52         protected $app;
53
54         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 = [])
55         {
56                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
57
58                 $this->session     = $session;
59                 $this->sysMessages = $sysMessages;
60                 $this->page        = $page;
61                 $this->app         = $app;
62         }
63
64         protected function content(array $request = []): string
65         {
66                 $nickname = $this->parameters['nickname'] ?? $this->app->getLoggedInUserNickname();
67                 if (!$nickname) {
68                         throw new HTTPException\UnauthorizedException();
69                 }
70
71                 $owner = User::getOwnerDataByNick($nickname);
72                 if (!$owner || $owner['account_expired'] || $owner['account_removed']) {
73                         throw new HTTPException\NotFoundException($this->t('User not found.'));
74                 }
75
76                 if (!$this->session->isAuthenticated() && $owner['hidewall']) {
77                         $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
78                 }
79
80                 if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) {
81                         $this->sysMessages->addNotice($this->t('Permission denied.'));
82                         return Login::form();
83                 }
84
85                 // get the translation strings for the calendar
86                 $i18n = Event::getStrings();
87
88                 $this->page->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
89                 $this->page->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
90                 $this->page->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
91                 $this->page->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
92
93                 $is_owner = $nickname == $this->app->getLoggedInUserNickname();
94
95                 $htpl = Renderer::getMarkupTemplate('calendar/calendar_head.tpl');
96                 $this->page['htmlhead'] .= Renderer::replaceMacros($htpl, [
97                         '$calendar_api' => 'calendar/api/get' . ($is_owner ? '' : '/' . $nickname),
98                         '$event_api'    => 'calendar/event/show' . ($is_owner ? '' : '/' . $nickname),
99                         '$modparams'    => 2,
100                         '$i18n'         => $i18n,
101                 ]);
102
103                 Nav::setSelected($is_owner ? 'home' : 'calendar');
104
105                 if (!$is_owner) {
106                         $this->page['aside'] .= Widget\VCard::getHTML($owner);
107                 }
108
109                 $this->page['aside'] .= Widget\CalendarExport::getHTML($owner['uid']);
110
111                 $tabs = BaseProfile::getTabsHTML('calendar', $is_owner, $nickname, !$is_owner && $owner['hide-friends']);
112
113                 // ACL blocks are loaded in modals in frio
114                 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
115                 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
116                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
117                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
118
119                 $tpl = Renderer::getMarkupTemplate("calendar/calendar.tpl");
120                 $o   = Renderer::replaceMacros($tpl, [
121                         '$tabs'      => $tabs,
122                         '$title'     => $this->t('Events'),
123                         '$view'      => $this->t('View'),
124                         '$new_event' => ['calendar/event/new', $this->t('Create New Event'), '', ''],
125
126                         '$today' => $this->t('today'),
127                         '$month' => $this->t('month'),
128                         '$week'  => $this->t('week'),
129                         '$day'   => $this->t('day'),
130                         '$list'  => $this->t('list'),
131                 ]);
132
133                 return $o;
134         }
135 }