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;
13 function tagrm_post(App $a)
16 $a->internalRedirect($_SESSION['photo_return']);
19 if (x($_POST,'submit') && ($_POST['submit'] === L10n::t('Cancel'))) {
20 $a->internalRedirect($_SESSION['photo_return']);
24 if (defaults($_POST, 'tag', '')){
25 foreach ($_POST['tag'] as $t){
26 array_push($tags, hex2bin(notags(trim($t))));
30 $item_id = defaults($_POST,'item', 0);
31 update_tags($item_id, $tags);
33 info(L10n::t('Tag(s) removed') . EOL );
35 $a->internalRedirect($_SESSION['photo_return']);
40 function update_tags($item_id, $tags){
41 if (empty($item_id) || empty($tags)){
42 $a->internalRedirect($_SESSION['photo_return']);
45 $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
46 if (!DBA::isResult($item)) {
47 $a->internalRedirect($_SESSION['photo_return']);
50 $arr = explode(',', $item['tag']);
52 foreach ($tags as $t) {
53 foreach ($arr as $i => $x) {
54 if (strcmp($x, $t) == 0) {
61 $tag_str = implode(',',$arr);
66 Item::update(['tag' => $tag_str], ['id' => $item_id]);
68 info(L10n::t('Tag(s) removed') . EOL );
69 $a->internalRedirect($_SESSION['photo_return']);
74 function tagrm_content(App $a)
79 $a->internalRedirect($_SESSION['photo_return']);
84 update_tags($a->argv[1], [hex2bin(notags(trim($a->argv[2])))]);
85 goaway('/' . $_SESSION['photo_return']);
88 $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
90 $a->internalRedirect($_SESSION['photo_return']);
94 $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
95 if (!DBA::isResult($item)) {
96 $a->internalRedirect($_SESSION['photo_return']);
99 $arr = explode(',', $item['tag']);
102 if (empty($item['tag'])) {
103 $a->internalRedirect($_SESSION['photo_return']);
106 $o .= '<h3>' . L10n::t('Remove Item Tag') . '</h3>';
108 $o .= '<p id="tag-remove-desc">' . L10n::t('Select a tag to remove: ') . '</p>';
110 $o .= '<form id="tagrm" action="tagrm" method="post" >';
111 $o .= '<input type="hidden" name="item" value="' . $item_id . '" />';
114 foreach ($arr as $x) {
115 $o .= '<li><input type="checkbox" name="tag[]" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
119 $o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . L10n::t('Remove') .'" />';
120 $o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . L10n::t('Cancel') .'" />';