7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\L10n;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Item;
11 use Friendica\Model\Term;
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 foreach (defaults($_POST, 'tag', []) as $tag) {
25 $tags[] = hex2bin(notags(trim($tag)));
28 $item_id = defaults($_POST,'item', 0);
29 update_tags($item_id, $tags);
30 info(L10n::t('Tag(s) removed') . EOL);
32 $a->internalRedirect($_SESSION['photo_return']);
37 * Updates tags from an item
41 function update_tags($item_id, $tags){
42 if (empty($item_id) || empty($tags)){
46 $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
47 if (!DBA::isResult($item)) {
51 $old_tags = explode(',', $item['tag']);
53 foreach ($tags as $new_tag) {
54 foreach ($old_tags as $index => $old_tag) {
55 if (strcmp($old_tag, $new_tag) == 0) {
56 unset($old_tags[$index]);
62 $tag_str = implode(',', $old_tags);
63 Term::insertFromTagFieldByItemId($item_id, $tag_str);
66 function tagrm_content(App $a)
71 $a->internalRedirect($_SESSION['photo_return']);
76 update_tags($a->argv[1], [notags(trim(hex2bin($a->argv[2])))]);
77 $a->internalRedirect($_SESSION['photo_return']);
80 $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
82 $a->internalRedirect($_SESSION['photo_return']);
86 $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
87 if (!DBA::isResult($item)) {
88 $a->internalRedirect($_SESSION['photo_return']);
91 $arr = explode(',', $item['tag']);
94 if (empty($item['tag'])) {
95 $a->internalRedirect($_SESSION['photo_return']);
98 $o .= '<h3>' . L10n::t('Remove Item Tag') . '</h3>';
100 $o .= '<p id="tag-remove-desc">' . L10n::t('Select a tag to remove: ') . '</p>';
102 $o .= '<form id="tagrm" action="tagrm" method="post" >';
103 $o .= '<input type="hidden" name="item" value="' . $item_id . '" />';
106 foreach ($arr as $x) {
107 $o .= '<li><input type="checkbox" name="tag[]" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
111 $o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . L10n::t('Remove') .'" />';
112 $o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . L10n::t('Cancel') .'" />';