]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Item/Delete.php
Added type hints
[friendica.git] / src / Module / Admin / Item / Delete.php
1 <?php
2
3 namespace Friendica\Module\Admin\Item;
4
5 use Friendica\Core\L10n;
6 use Friendica\Core\Renderer;
7 use Friendica\DI;
8 use Friendica\Model\Item;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Util\Strings;
11
12 class Delete extends BaseAdminModule
13 {
14         public static function post(array $parameters = [])
15         {
16                 parent::post($parameters);
17
18                 if (empty($_POST['page_deleteitem_submit'])) {
19                         return;
20                 }
21
22                 parent::checkFormSecurityTokenRedirectOnError('/admin/item/delete', 'admin_deleteitem');
23
24                 if (!empty($_POST['page_deleteitem_submit'])) {
25                         $guid = trim(Strings::escapeTags($_POST['deleteitemguid']));
26                         // The GUID should not include a "/", so if there is one, we got an URL
27                         // and the last part of it is most likely the GUID.
28                         if (strpos($guid, '/')) {
29                                 $guid = substr($guid, strrpos($guid, '/') + 1);
30                         }
31                         // Now that we have the GUID, drop those items, which will also delete the
32                         // associated threads.
33                         Item::delete(['guid' => $guid]);
34                 }
35
36                 info(L10n::t('Item marked for deletion.') . EOL);
37                 DI::baseUrl()->redirect('admin/item/delete');
38         }
39
40         public static function content(array $parameters = [])
41         {
42                 parent::content($parameters);
43
44                 $t = Renderer::getMarkupTemplate('admin/item/delete.tpl');
45
46                 return Renderer::replaceMacros($t, [
47                         '$title' => L10n::t('Administration'),
48                         '$page' => L10n::t('Delete Item'),
49                         '$submit' => L10n::t('Delete this Item'),
50                         '$intro1' => 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.'),
51                         '$intro2' => 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.'),
52                         '$deleteitemguid' => ['deleteitemguid', L10n::t("GUID"), '', L10n::t("The GUID of the item you want to delete."), 'required', 'autofocus'],
53                         '$form_security_token' => parent::getFormSecurityToken("admin_deleteitem")
54                 ]);
55         }
56 }