Update copyright
[friendica.git/.git] / src / Module / Debug / Localtime.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Debug;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Installer;
26 use Friendica\DI;
27 use Friendica\Util\DateTimeFormat;
28 use Friendica\Util\Temporal;
29
30 class Localtime extends BaseModule
31 {
32         public static function post(array $parameters = [])
33         {
34                 $time = ($_REQUEST['time'] ?? '') ?: 'now';
35
36                 $bd_format = DI::l10n()->t('l F d, Y \@ g:i A');
37
38                 if (!empty($_POST['timezone'])) {
39                         DI::app()->data['mod-localtime'] = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format);
40                 }
41         }
42
43         public static function content(array $parameters = [])
44         {
45                 $app = DI::app();
46
47                 $time = ($_REQUEST['time'] ?? '') ?: 'now';
48
49                 $output  = '<h3>' . DI::l10n()->t('Time Conversion') . '</h3>';
50                 $output .= '<p>' . DI::l10n()->t('Friendica provides this service for sharing events with other networks and friends in unknown timezones.') . '</p>';
51                 $output .= '<p>' . DI::l10n()->t('UTC time: %s', $time) . '</p>';
52
53                 if (!empty($_REQUEST['timezone'])) {
54                         $output .= '<p>' . DI::l10n()->t('Current timezone: %s', $_REQUEST['timezone']) . '</p>';
55                 }
56
57                 if (!empty($app->data['mod-localtime'])) {
58                         $output .= '<p>' . DI::l10n()->t('Converted localtime: %s', $app->data['mod-localtime']) . '</p>';
59                 }
60
61                 $output .= '<form action ="' . DI::baseUrl()->get() . '/localtime?time=' . $time . '" method="post" >';
62                 $output .= '<p>' . DI::l10n()->t('Please select your timezone:') . '</p>';
63                 $output .= Temporal::getTimezoneSelect(($_REQUEST['timezone'] ?? '') ?: Installer::DEFAULT_TZ);
64                 $output .= '<input type="submit" name="submit" value="' . DI::l10n()->t('Submit') . '" /></form>';
65
66                 return $output;
67         }
68 }