3 * @copyright Copyright (C) 2010-2023, 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\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;
44 class Show extends BaseModule
46 /** @var IHandleUserSessions */
48 /** @var SystemMessages */
49 protected $sysMessages;
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 = [])
57 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
59 $this->session = $session;
60 $this->sysMessages = $sysMessages;
65 protected function content(array $request = []): string
67 $nickname = $this->parameters['nickname'] ?? $this->session->getLocalUserNickname();
69 throw new HTTPException\UnauthorizedException();
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.'));
77 if (!$this->session->isAuthenticated() && $owner['hidewall']) {
78 $this->baseUrl->redirect('profile/' . $nickname . '/restricted');
81 if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) {
82 $this->sysMessages->addNotice($this->t('Permission denied.'));
86 // get the translation strings for the calendar
87 $i18n = Event::getStrings();
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');
94 $is_owner = $nickname == $this->app->getLoggedInUserNickname();
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),
104 Nav::setSelected($is_owner ? 'home' : 'calendar');
107 // Removing the vCard added by Profile::load for owners
108 $this->page['aside'] = '';
111 $this->page['aside'] .= Widget\CalendarExport::getHTML($owner['uid']);
113 $tabs = BaseProfile::getTabsHTML('calendar', $is_owner, $nickname, !$is_owner && $owner['hide-friends']);
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'));
121 $tpl = Renderer::getMarkupTemplate("calendar/calendar.tpl");
122 $o = Renderer::replaceMacros($tpl, [
124 '$title' => $this->t('Events'),
125 '$view' => $this->t('View'),
126 '$new_event' => ['calendar/event/new', $this->t('Create New Event'), '', ''],
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'),