]> git.mxchange.org Git - friendica.git/blob - mod/tagrm.php
Ops, one more left ...
[friendica.git] / mod / tagrm.php
1 <?php
2 /**
3  * @file mod/tagrm.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Model\Item;
12
13 function tagrm_post(App $a)
14 {
15         if (!local_user()) {
16                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
17         }
18
19         if (x($_POST,'submit') && ($_POST['submit'] === L10n::t('Cancel'))) {
20                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
21         }
22
23         $tag =  (x($_POST,'tag')  ? hex2bin(notags(trim($_POST['tag']))) : '');
24         $item_id = (x($_POST,'item') ? intval($_POST['item'])               : 0);
25
26         $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
27         if (!DBA::isResult($item)) {
28                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
29         }
30
31         $arr = explode(',', $item['tag']);
32         for ($x = 0; $x < count($arr); $x ++) {
33                 if ($arr[$x] === $tag) {
34                         unset($arr[$x]);
35                         break;
36                 }
37         }
38
39         $tag_str = implode(',',$arr);
40
41         Item::update(['tag' => $tag_str], ['id' => $item_id]);
42
43         info(L10n::t('Tag removed') . EOL );
44         goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
45
46         // NOTREACHED
47 }
48
49
50
51 function tagrm_content(App $a)
52 {
53         $o = '';
54
55         if (!local_user()) {
56                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
57                 // NOTREACHED
58         }
59
60         $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
61         if (!$item_id) {
62                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
63                 // NOTREACHED
64         }
65
66         $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
67         if (!DBA::isResult($item)) {
68                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
69         }
70
71         $arr = explode(',', $item['tag']);
72
73         if (!count($arr)) {
74                 goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
75         }
76
77         $o .= '<h3>' . L10n::t('Remove Item Tag') . '</h3>';
78
79         $o .= '<p id="tag-remove-desc">' . L10n::t('Select a tag to remove: ') . '</p>';
80
81         $o .= '<form id="tagrm" action="tagrm" method="post" >';
82         $o .= '<input type="hidden" name="item" value="' . $item_id . '" />';
83         $o .= '<ul>';
84
85         foreach ($arr as $x) {
86                 $o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
87         }
88
89         $o .= '</ul>';
90         $o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . L10n::t('Remove') .'" />';
91         $o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . L10n::t('Cancel') .'" />';
92         $o .= '</form>';
93
94         return $o;
95 }