]> git.mxchange.org Git - friendica.git/commitdiff
Move new events routes to calendar routes
authorPhilipp <admin@philipp.info>
Wed, 2 Nov 2022 07:59:46 +0000 (08:59 +0100)
committerPhilipp <admin@philipp.info>
Wed, 2 Nov 2022 14:16:24 +0000 (15:16 +0100)
src/Module/Calendar/Export.php [new file with mode: 0644]
src/Module/Calendar/Json.php [new file with mode: 0644]
src/Module/Events/Export.php [deleted file]
src/Module/Events/Json.php [deleted file]
static/routes.config.php
view/templates/event_head.tpl
view/templates/widget/events.tpl
view/theme/quattro/templates/events_reminder.tpl
view/theme/vier/templates/event_head.tpl

diff --git a/src/Module/Calendar/Export.php b/src/Module/Calendar/Export.php
new file mode 100644 (file)
index 0000000..30a1bc4
--- /dev/null
@@ -0,0 +1,109 @@
+<?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/>.
+ *
+ */
+
+namespace Friendica\Module\Calendar;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Model\Event;
+use Friendica\Model\User;
+use Friendica\Module\Response;
+use Friendica\Navigation\SystemMessages;
+use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Controller to export a calendar from a given user
+ */
+class Export extends BaseModule
+{
+       const EXPORT_ICAL = 'ical';
+       const EXPORT_CSV  = 'csv';
+
+       const DEFAULT_EXPORT = self::EXPORT_ICAL;
+
+       /** @var IHandleUserSessions */
+       protected $session;
+       /** @var SystemMessages */
+       protected $sysMessages;
+
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->session     = $session;
+               $this->sysMessages = $sysMessages;
+       }
+
+       protected function rawContent(array $request = [])
+       {
+               $owner = User::getByNickname($this->parameters['nickname'], ['uid']);
+               if (empty($owner)) {
+                       throw new HTTPException\NotFoundException($this->t('User not found.'));
+               }
+               $ownerUid = $owner['uid'];
+               $format   = $this->parameters['format'] ?: static::DEFAULT_EXPORT;
+
+               // Get the export data by uid
+               $evexport = Event::exportListByUserId($ownerUid, $format);
+
+               if (!$evexport["success"]) {
+                       if ($evexport["content"]) {
+                               $this->sysMessages->addNotice($this->t('This calendar format is not supported'));
+                       } else {
+                               $this->sysMessages->addNotice($this->t('No exportable data found'));
+                       }
+
+                       // If it is the own calendar return to the events page
+                       // otherwise to the profile calendar page
+                       if ($this->session->getLocalUserId() === $ownerUid) {
+                               $returnPath = 'events';
+                       } else {
+                               $returnPath = 'events/' . $this->parameters['nickname'];
+                       }
+
+                       $this->baseUrl->redirect($returnPath);
+               }
+
+               // If nothing went wrong we can echo the export content
+               if ($evexport["success"]) {
+                       $this->response->setHeader(sprintf('Content-Disposition: attachment; filename="%s-%s.%s"',
+                               $this->t('calendar'),
+                               $this->parameters['nickname'],
+                               $evexport["extension"]
+                       ));
+
+                       switch ($format) {
+                               case static::EXPORT_ICAL:
+                                       $this->response->setType(Response::TYPE_BLANK, 'text/ics');
+                                       break;
+                               case static::EXPORT_CSV:
+                                       $this->response->setType(Response::TYPE_BLANK, 'text/csv');
+                                       break;
+                       }
+
+                       $this->response->addContent($evexport['content']);
+               }
+       }
+}
diff --git a/src/Module/Calendar/Json.php b/src/Module/Calendar/Json.php
new file mode 100644 (file)
index 0000000..08481e6
--- /dev/null
@@ -0,0 +1,122 @@
+<?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/>.
+ *
+ */
+
+namespace Friendica\Module\Calendar;
+
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Event;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Network\HTTPException;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Temporal;
+
+class Json extends \Friendica\BaseModule
+{
+       protected function rawContent(array $request = [])
+       {
+               if (!DI::userSession()->getLocalUserId()) {
+                       throw new HTTPException\UnauthorizedException();
+               }
+
+               $y = intval(DateTimeFormat::localNow('Y'));
+               $m = intval(DateTimeFormat::localNow('m'));
+
+               // Put some limit on dates. The PHP date functions don't seem to do so well before 1900.
+               if ($y < 1901) {
+                       $y = 1900;
+               }
+
+               $dim    = Temporal::getDaysInMonth($y, $m);
+               $start  = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
+               $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
+
+               if (!empty($request['start'])) {
+                       $start = $request['start'];
+               }
+
+               if (!empty($request['end'])) {
+                       $finish = $request['end'];
+               }
+
+               // put the event parametes in an array so we can better transmit them
+               $event_params = [
+                       'event_id' => intval($request['id'] ?? 0),
+                       'start'    => $start,
+                       'finish'   => $finish,
+                       'ignore'   => 0,
+               ];
+
+               // get events by id or by date
+               if ($event_params['event_id']) {
+                       $r = Event::getListById(DI::userSession()->getLocalUserId(), $event_params['event_id']);
+               } else {
+                       $r = Event::getListByDate(DI::userSession()->getLocalUserId(), $event_params);
+               }
+
+               $links = [];
+
+               if (DBA::isResult($r)) {
+                       $r = Event::sortByDate($r);
+                       foreach ($r as $rr) {
+                               $j = DateTimeFormat::utc($rr['start'], 'j');
+                               if (empty($links[$j])) {
+                                       $links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
+                               }
+                       }
+               }
+
+               $events = [];
+
+               // transform the event in a usable array
+               if (DBA::isResult($r)) {
+                       $events = Event::sortByDate($r);
+
+                       $events = self::map($events);
+               }
+
+               System::jsonExit($events);
+       }
+
+       private static function map(array $events): array
+       {
+               return array_map(function ($event) {
+                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]);
+                       if (!DBA::isResult($item)) {
+                               // Using default values when no item had been found
+                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC, 'uri-id' => ($event['uri-id'] ?? 0)];
+                       }
+
+                       return [
+                               'id'       => $event['id'],
+                               'title'    => $event['summary'],
+                               'start'    => DateTimeFormat::local($event['start']),
+                               'end'      => DateTimeFormat::local($event['finish']),
+                               'nofinish' => $event['nofinish'],
+                               'desc'     => $event['desc'],
+                               'location' => $event['location'],
+                               'item'     => $item,
+                       ];
+               }, $events);
+       }
+}
diff --git a/src/Module/Events/Export.php b/src/Module/Events/Export.php
deleted file mode 100644 (file)
index fef3ed8..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-<?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/>.
- *
- */
-
-namespace Friendica\Module\Events;
-
-use Friendica\App;
-use Friendica\BaseModule;
-use Friendica\Core\L10n;
-use Friendica\Core\Session\Capability\IHandleUserSessions;
-use Friendica\Model\Event;
-use Friendica\Model\User;
-use Friendica\Module\Response;
-use Friendica\Navigation\SystemMessages;
-use Friendica\Network\HTTPException;
-use Friendica\Util\Profiler;
-use Psr\Log\LoggerInterface;
-
-/**
- * Controller to export calendar
- */
-class Export extends BaseModule
-{
-       const EXPORT_ICAL = 'ical';
-       const EXPORT_CSV  = 'csv';
-
-       const DEFAULT_EXPORT = self::EXPORT_ICAL;
-
-       /** @var IHandleUserSessions */
-       protected $session;
-       /** @var SystemMessages */
-       protected $sysMessages;
-
-       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, array $server, array $parameters = [])
-       {
-               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
-
-               $this->session     = $session;
-               $this->sysMessages = $sysMessages;
-       }
-
-       protected function rawContent(array $request = [])
-       {
-               $owner = User::getByNickname($this->parameters['nickname'], ['uid']);
-               if (empty($owner)) {
-                       throw new HTTPException\NotFoundException($this->t('User not found.'));
-               }
-               $ownerUid = $owner['uid'];
-               $format   = $this->parameters['format'] ?: static::DEFAULT_EXPORT;
-
-               // Get the export data by uid
-               $evexport = Event::exportListByUserId($ownerUid, $format);
-
-               if (!$evexport["success"]) {
-                       if ($evexport["content"]) {
-                               $this->sysMessages->addNotice($this->t('This calendar format is not supported'));
-                       } else {
-                               $this->sysMessages->addNotice($this->t('No exportable data found'));
-                       }
-
-                       // If it is the own calendar return to the events page
-                       // otherwise to the profile calendar page
-                       if ($this->session->getLocalUserId() === $ownerUid) {
-                               $returnPath = 'events';
-                       } else {
-                               $returnPath = 'events/' . $this->parameters['nickname'];
-                       }
-
-                       $this->baseUrl->redirect($returnPath);
-               }
-
-               // If nothing went wrong we can echo the export content
-               if ($evexport["success"]) {
-                       $this->response->setHeader(sprintf('content-disposition: attachment; filename="%s-%s.%s"',
-                               $this->t('calendar'),
-                               $this->parameters['nickname'],
-                               $evexport["extension"]
-                       ));
-
-                       switch ($format) {
-                               case static::EXPORT_ICAL:
-                                       $this->response->setType(Response::TYPE_BLANK, 'text/ics');
-                                       break;
-                               case static::EXPORT_CSV:
-                                       $this->response->setType(Response::TYPE_BLANK, 'text/csv');
-                                       break;
-                       }
-
-                       $this->response->addContent($evexport['content']);
-               }
-       }
-}
diff --git a/src/Module/Events/Json.php b/src/Module/Events/Json.php
deleted file mode 100644 (file)
index 2072c4f..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-<?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/>.
- *
- */
-
-namespace Friendica\Module\Events;
-
-use Friendica\Core\System;
-use Friendica\Database\DBA;
-use Friendica\DI;
-use Friendica\Model\Event;
-use Friendica\Model\Item;
-use Friendica\Model\Post;
-use Friendica\Network\HTTPException;
-use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Temporal;
-
-class Json extends \Friendica\BaseModule
-{
-       protected function rawContent(array $request = [])
-       {
-               if (!DI::userSession()->getLocalUserId()) {
-                       throw new HTTPException\UnauthorizedException();
-               }
-
-               $y = intval(DateTimeFormat::localNow('Y'));
-               $m = intval(DateTimeFormat::localNow('m'));
-
-               // Put some limit on dates. The PHP date functions don't seem to do so well before 1900.
-               if ($y < 1901) {
-                       $y = 1900;
-               }
-
-               $dim    = Temporal::getDaysInMonth($y, $m);
-               $start  = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
-               $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
-
-               if (!empty($_GET['start'])) {
-                       $start = $_GET['start'];
-               }
-
-               if (!empty($_GET['end'])) {
-                       $finish = $_GET['end'];
-               }
-
-               // 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,
-                       'ignore'   => 0,
-               ];
-
-               // get events by id or by date
-               if ($event_params['event_id']) {
-                       $r = Event::getListById(DI::userSession()->getLocalUserId(), $event_params['event_id']);
-               } else {
-                       $r = Event::getListByDate(DI::userSession()->getLocalUserId(), $event_params);
-               }
-
-               $links = [];
-
-               if (DBA::isResult($r)) {
-                       $r = Event::sortByDate($r);
-                       foreach ($r as $rr) {
-                               $j = DateTimeFormat::utc($rr['start'], 'j');
-                               if (empty($links[$j])) {
-                                       $links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
-                               }
-                       }
-               }
-
-               $events = [];
-
-               // transform the event in a usable array
-               if (DBA::isResult($r)) {
-                       $events = Event::sortByDate($r);
-
-                       $events = self::map($events);
-               }
-
-               System::jsonExit($events);
-       }
-
-       private static function map(array $events): array
-       {
-               return array_map(function ($event) {
-                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]);
-                       if (!DBA::isResult($item)) {
-                               // Using default values when no item had been found
-                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC, 'uri-id' => ($event['uri-id'] ?? 0)];
-                       }
-
-                       return [
-                               'id'       => $event['id'],
-                               'title'    => $event['summary'],
-                               'start'    => DateTimeFormat::local($event['start']),
-                               'end'      => DateTimeFormat::local($event['finish']),
-                               'nofinish' => $event['nofinish'],
-                               'desc'     => $event['desc'],
-                               'location' => $event['location'],
-                               'item'     => $item,
-                       ];
-               }, $events);
-       }
-}
index e344de75cc1c174e9df305db8f3c3348d1b7c9e5..e3098c3ae80858d059c8b3609a5dffc9b2071006 100644 (file)
@@ -365,6 +365,9 @@ return [
 
        '/bookmarklet'         => [Module\Bookmarklet::class,  [R::GET]],
 
+       '/calendar/{nickname}/export[/{format}]' => [Module\Calendar\Export::class, [R::GET]],
+       '/calendar/json'                           => [Module\Calendar\Json::class, [R::GET]],
+
        '/community[/{content}]' => [Module\Conversation\Community::class, [R::GET]],
 
        '/compose[/{type}]'    => [Module\Item\Compose::class, [R::GET, R::POST]],
@@ -398,9 +401,6 @@ return [
        '/dirfind'                  => [Module\Search\Directory::class, [R::GET]],
        '/directory'                => [Module\Directory::class,        [R::GET]],
 
-       '/events/{nickname}/export[/{format}]' => [Module\Events\Export::class, [R::GET]],
-       '/events/json'                         => [Module\Events\Json::class,   [R::GET]],
-
        '/featured/{nickname}'      => [Module\ActivityPub\Featured::class, [R::GET]],
 
        '/feed'     => [
index 3075408063c9fb66aaeabe6da424f9779d9b3b7c..1627bd69969a8f6dbc993462c9470253e3d1fc39 100644 (file)
@@ -81,7 +81,7 @@
                                week: '{{$i18n.week|escape:'quotes'}}',
                                day: '{{$i18n.day|escape:'quotes'}}'
                        },
-                       events: '{{$baseurl}}{{$module_url}}/json/',
+                       events: '{{$baseurl}}/calendar/json',
                        header: {
                                left: 'prev,next today',
                                center: 'title',
index c83542778ea236850b93383c5bd0fc68f324cc65..10f142cb3959fb506d5f299d8744e05bd97919a6 100644 (file)
@@ -3,7 +3,7 @@
        <h3>{{$etitle}}</h3>
 
        <ul class="sidebar-calendar-export-ul">
-               <li role="menuitem" class="sidebar-calendar-export-li"><a href="{{$baseurl}}/events/{{$user}}/export/ical">{{$export_ical}}</a></li>
-               <li role="menuitem" class="sidebar-calendar-export-li"><a href="{{$baseurl}}/events/{{$user}}/export/csv">{{$export_csv}}</a></li>
+               <li role="menuitem" class="sidebar-calendar-export-li"><a href="{{$baseurl}}/calendar/{{$user}}/export/ical">{{$export_ical}}</a></li>
+               <li role="menuitem" class="sidebar-calendar-export-li"><a href="{{$baseurl}}/calendar/{{$user}}/export/csv">{{$export_csv}}</a></li>
        </ul>
 </div>
index d0bc1f481c0fd1c0e351df01d33e278a0ab878c4..e72384f3231702f8c997ece1dbdc4362591f13b6 100644 (file)
@@ -22,7 +22,7 @@
                        year: yesterday.getFullYear(),
                        month: yesterday.getMonth(),
                        date: yesterday.getDate(),
-                       events: '{{$baseurl}}/events/json/',
+                       events: '{{$baseurl}}/calendar/json/',
                        header: false,
                        timeFormat: 'H(:mm)',
                        defaultView: 'basicWeek',
index 2c7b3070a74e5c4225205e3bfd1d0e3493136348..817204a31c29ddd71c94e74a984c8c6a0918e68d 100644 (file)
@@ -87,7 +87,7 @@
                                week: '{{$i18n.week|escape:'quotes'}}',
                                day: '{{$i18n.day|escape:'quotes'}}'
                        },
-                       events: '{{$baseurl}}{{$module_url}}/json/',
+                       events: '{{$baseurl}}/calendar/json',
                        header: {
                                left: 'prev,next today',
                                center: 'title',