]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Item/Delete.php
f34ce7238108e5e8eb5514f124ee5c15c0ed2d1b
[friendica.git] / src / Module / Admin / Item / Delete.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\Admin\Item;
23
24 use Friendica\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Model\Item;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Strings;
29
30 class Delete extends BaseAdmin
31 {
32         public static function post(array $parameters = [])
33         {
34                 self::checkAdminAccess();
35
36                 if (empty($_POST['page_deleteitem_submit'])) {
37                         return;
38                 }
39
40                 self::checkFormSecurityTokenRedirectOnError('/admin/item/delete', 'admin_deleteitem');
41
42                 if (!empty($_POST['page_deleteitem_submit'])) {
43                         $guid = trim(Strings::escapeTags($_POST['deleteitemguid']));
44                         // The GUID should not include a "/", so if there is one, we got an URL
45                         // and the last part of it is most likely the GUID.
46                         if (strpos($guid, '/')) {
47                                 $guid = substr($guid, strrpos($guid, '/') + 1);
48                         }
49                         // Now that we have the GUID, drop those items, which will also delete the
50                         // associated threads.
51                         Item::markForDeletion(['guid' => $guid]);
52                 }
53
54                 info(DI::l10n()->t('Item marked for deletion.'));
55                 DI::baseUrl()->redirect('admin/item/delete');
56         }
57
58         public static function content(array $parameters = [])
59         {
60                 parent::content($parameters);
61
62                 $t = Renderer::getMarkupTemplate('admin/item/delete.tpl');
63
64                 return Renderer::replaceMacros($t, [
65                         '$title' => DI::l10n()->t('Administration'),
66                         '$page' => DI::l10n()->t('Delete Item'),
67                         '$submit' => DI::l10n()->t('Delete this Item'),
68                         '$intro1' => DI::l10n()->t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
69                         '$intro2' => DI::l10n()->t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
70                         '$deleteitemguid' => ['deleteitemguid', DI::l10n()->t("GUID"), '', DI::l10n()->t("The GUID of the item you want to delete."), DI::l10n()->t('Required'), 'autofocus'],
71                         '$form_security_token' => self::getFormSecurityToken("admin_deleteitem")
72                 ]);
73         }
74 }