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