]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Schedule.php
Merge pull request #12028 from annando/no-boot-src-module-4
[friendica.git] / src / Module / Profile / Schedule.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\Profile;
23
24 use Friendica\BaseModule;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session;
28 use Friendica\Database\DBA;
29 use Friendica\DI;
30 use Friendica\Model\Post;
31 use Friendica\Module\BaseProfile;
32 use Friendica\Network\HTTPException;
33 use Friendica\Util\DateTimeFormat;
34
35 class Schedule extends BaseProfile
36 {
37         protected function post(array $request = [])
38         {
39                 if (!Session::getLocalUser()) {
40                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
41                 }
42
43                 if (empty($_REQUEST['delete'])) {
44                         throw new HTTPException\BadRequestException();
45                 }
46
47                 if (!DBA::exists('delayed-post', ['id' => $_REQUEST['delete'], 'uid' => Session::getLocalUser()])) {
48                         throw new HTTPException\NotFoundException();
49                 }
50
51                 Post\Delayed::deleteById($_REQUEST['delete']);
52         }
53
54         protected function content(array $request = []): string
55         {
56                 if (!Session::getLocalUser()) {
57                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
58                 }
59
60                 $a = DI::app();
61
62                 $o = self::getTabsHTML($a, 'schedule', true, $a->getLoggedInUserNickname(), false);
63
64                 $schedule = [];
65                 $delayed = DBA::select('delayed-post', [], ['uid' => Session::getLocalUser()]);
66                 while ($row = DBA::fetch($delayed)) {
67                         $parameter = Post\Delayed::getParametersForid($row['id']);
68                         if (empty($parameter)) {
69                                 continue;
70                         }
71                         $schedule[] = [
72                                 'id'           => $row['id'],
73                                 'scheduled_at' => DateTimeFormat::local($row['delayed']),
74                                 'content'      => BBCode::toPlaintext($parameter['item']['body'], false)
75                         ];
76                 }
77                 DBA::close($delayed);
78
79                 $tpl = Renderer::getMarkupTemplate('profile/schedule.tpl');
80                 $o .= Renderer::replaceMacros($tpl, [
81                         '$form_security_token' => BaseModule::getFormSecurityToken("profile_schedule"),
82                         '$baseurl'             => DI::baseUrl()->get(true),
83                         '$title'               => DI::l10n()->t('Scheduled Posts'),
84                         '$nickname'            => $this->parameters['nickname'] ?? '',
85                         '$scheduled_at'        => DI::l10n()->t('Scheduled'),
86                         '$content'             => DI::l10n()->t('Content'),
87                         '$delete'              => DI::l10n()->t('Remove post'),
88                         '$schedule'            => $schedule,
89                 ]);
90
91                 return $o;
92         }
93 }