3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Calendar;
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;
43 class Show extends BaseModule
45 /** @var IHandleUserSessions */
47 /** @var SystemMessages */
48 protected $sysMessages;
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 = [])
56 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
58 $this->session = $session;
59 $this->sysMessages = $sysMessages;
64 protected function content(array $request = []): string
66 $nickname = $this->parameters['nickname'] ?? $this->app->getLoggedInUserNickname();
68 throw new HTTPException\UnauthorizedException();
71 $owner = User::getOwnerDataByNick($nickname);
72 if (!$owner || $owner['account_expired'] || $owner['account_removed']) {
73 throw new HTTPException\NotFoundException($this->t('User not found.'));
76 if (!$this->session->isAuthenticated() && $owner['hidewall']) {
77 $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
80 if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) {
81 $this->sysMessages->addNotice($this->t('Permission denied.'));
85 // get the translation strings for the calendar
86 $i18n = Event::getStrings();
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');
93 $is_owner = $nickname == $this->app->getLoggedInUserNickname();
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),
103 Nav::setSelected($is_owner ? 'home' : 'calendar');
106 $this->page['aside'] .= Widget\VCard::getHTML($owner);
109 $this->page['aside'] .= Widget\CalendarExport::getHTML($owner['uid']);
111 $tabs = BaseProfile::getTabsHTML('calendar', $is_owner, $nickname, !$is_owner && $owner['hide-friends']);
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'));
119 $tpl = Renderer::getMarkupTemplate("calendar/calendar.tpl");
120 $o = Renderer::replaceMacros($tpl, [
122 '$title' => $this->t('Events'),
123 '$view' => $this->t('View'),
124 '$new_event' => ['calendar/event/new', $this->t('Create New Event'), '', ''],
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'),