From fd2e06781ddb4203c0d1254b9d3e4b9a8e9934e9 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 11:40:20 +0200 Subject: [PATCH 01/10] Fix adding / removing photo tags + tagrm delete via GET + Item::update / add Term::deleteAllTags --- mod/photos.php | 16 ++++---- mod/tagrm.php | 51 +++++++++++++++++++----- src/Model/Item.php | 14 ++++--- src/Model/Term.php | 15 +++++++ view/theme/frio/templates/photo_view.tpl | 13 ++++-- 5 files changed, 81 insertions(+), 28 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 008d59cd9c..65ad9b5d4b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -612,7 +612,7 @@ function photos_post(App $a) } } elseif (strpos($tag, '#') === 0) { $tagname = substr($tag, 1); - $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]'; + $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],'; } } } @@ -1417,17 +1417,15 @@ function photos_content(App $a) if (count($linked_items) && strlen($link_item['tag'])) { $arr = explode(',', $link_item['tag']); // parse tags and add links - $tag_str = ''; + $tag_arr = []; foreach ($arr as $t) { - if (strlen($tag_str)) { - $tag_str .= ', '; - } - $tag_str .= BBCode::convert($t); + array_push($tag_arr, ['name' => BBCode::convert($t), + 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($t)]); } - $tags = [L10n::t('Tags: '), $tag_str]; + $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { - $tags[] = 'tagrm/' . $link_item['id']; - $tags[] = L10n::t('[Remove any tag]'); + $tags += ['removeanyurl' => 'tagrm/' . $link_item['id']]; + $tags += ['removetitle' => L10n::t('[Remove any tag]')]; } } diff --git a/mod/tagrm.php b/mod/tagrm.php index 105cc0b3d5..39581efbb0 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -20,8 +20,27 @@ function tagrm_post(App $a) $a->internalRedirect($_SESSION['photo_return']); } - $tag = (x($_POST,'tag') ? hex2bin(notags(trim($_POST['tag']))) : ''); - $item_id = (x($_POST,'item') ? intval($_POST['item']) : 0); + $tags = []; + if (defaults($_POST, 'tag', '')){ + foreach ($_POST['tag'] as $t){ + array_push($tags, hex2bin(notags(trim($t)))); + } + } + + $item_id = defaults($_POST,'item', 0); + update_tags($item_id, $tags); + + info(L10n::t('Tag(s) removed') . EOL ); + + $a->internalRedirect($_SESSION['photo_return']); + + // NOTREACHED +} + +function update_tags($item_id, $tags){ + if (empty($item_id) || empty($tags)){ + $a->internalRedirect($_SESSION['photo_return']); + } $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]); if (!DBA::isResult($item)) { @@ -29,25 +48,29 @@ function tagrm_post(App $a) } $arr = explode(',', $item['tag']); - for ($x = 0; $x < count($arr); $x ++) { - if ($arr[$x] === $tag) { - unset($arr[$x]); - break; + + foreach ($tags as $t) { + foreach ($arr as $i => $x) { + if (strcmp($x, $t) == 0) { + unset($arr[$i]); + break; + } } } $tag_str = implode(',',$arr); + if(empty($tag_str)){ + $tag_str = ''; + } Item::update(['tag' => $tag_str], ['id' => $item_id]); - info(L10n::t('Tag removed') . EOL ); + info(L10n::t('Tag(s) removed') . EOL ); $a->internalRedirect($_SESSION['photo_return']); // NOTREACHED } - - function tagrm_content(App $a) { $o = ''; @@ -57,6 +80,11 @@ function tagrm_content(App $a) // NOTREACHED } + if ($a->argc == 3){ + update_tags($a->argv[1], [hex2bin(notags(trim($a->argv[2])))]); + goaway('/' . $_SESSION['photo_return']); + } + $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); if (!$item_id) { $a->internalRedirect($_SESSION['photo_return']); @@ -70,7 +98,8 @@ function tagrm_content(App $a) $arr = explode(',', $item['tag']); - if (!count($arr)) { + + if (empty($item['tag'])) { $a->internalRedirect($_SESSION['photo_return']); } @@ -83,7 +112,7 @@ function tagrm_content(App $a) $o .= ''; diff --git a/src/Model/Item.php b/src/Model/Item.php index 1c0b11db4a..9b016295ee 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -816,7 +816,7 @@ class Item extends BaseObject $tags = $fields['tag']; $fields['tag'] = null; } else { - $tags = ''; + $tags = null; } if (array_key_exists('file', $fields)) { @@ -895,10 +895,14 @@ class Item extends BaseObject } } - if (!empty($tags)) { - Term::insertFromTagFieldByItemId($item['id'], $tags); - if (!empty($item['tag'])) { - DBA::update('item', ['tag' => ''], ['id' => $item['id']]); + if (!is_null($tags)) { + Term::deleteAllTags($item['id']); + + if ($tags) { + Term::insertFromTagFieldByItemId($item['id'], $tags); + if (!empty($item['tag'])) { + DBA::update('item', ['tag' => ''], ['id' => $item['id']]); + } } } diff --git a/src/Model/Term.php b/src/Model/Term.php index 854861ccb5..6c89b5d00f 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -290,4 +290,19 @@ class Term return $return; } + + /* + * Deletes all Tags from an item + */ + public static function deleteAllTags($itemid) + { + $message = Item::selectFirst(['id'], ['id' => $itemid]); + if (!DBA::isResult($message)) { + return; + } + + // Clean up all tags + DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]); + + } } diff --git a/view/theme/frio/templates/photo_view.tpl b/view/theme/frio/templates/photo_view.tpl index e610926d4c..cc72a10fa2 100644 --- a/view/theme/frio/templates/photo_view.tpl +++ b/view/theme/frio/templates/photo_view.tpl @@ -51,12 +51,19 @@ {{* Tags and mentions *}} {{if $tags}} -
{{$tags.1}}
+
{{$tags.title}} + {{foreach $tags.tags as $t}} + + {{$t.name}} + {{if $t.removeurl}} (x) {{/if}} + + {{/foreach}} +
{{/if}} - {{if $tags.2}} + {{if $tags.removeanyurl}}
- {{$tags.3}} + {{$tags.removetitle}}
{{/if}} From 1689c440856e70687cabafda167cf9ee74fb3108 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 11:44:31 +0200 Subject: [PATCH 02/10] Fix goaway call --- mod/tagrm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index 39581efbb0..a6745e8e56 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -82,7 +82,7 @@ function tagrm_content(App $a) if ($a->argc == 3){ update_tags($a->argv[1], [hex2bin(notags(trim($a->argv[2])))]); - goaway('/' . $_SESSION['photo_return']); + $a->internalRedirect($_SESSION['photo_return']); } $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); From 272eb5eb820a03aff7bcb4e461e69c93d6dffab0 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 13:32:32 +0200 Subject: [PATCH 03/10] fix doxygen header + indent --- mod/tagrm.php | 5 +++++ src/Model/Term.php | 5 +++-- view/theme/frio/templates/photo_view.tpl | 12 ++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index a6745e8e56..4bdaeb32f1 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -37,6 +37,11 @@ function tagrm_post(App $a) // NOTREACHED } +/** + * Updates tags from an item + * @param $item_id + * @param $tags array + */ function update_tags($item_id, $tags){ if (empty($item_id) || empty($tags)){ $a->internalRedirect($_SESSION['photo_return']); diff --git a/src/Model/Term.php b/src/Model/Term.php index 6c89b5d00f..75cc100703 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -291,8 +291,9 @@ class Term return $return; } - /* - * Deletes all Tags from an item + /** + * Delete all tags from an item + * @param int itemid - choose from which item the tags will be removed */ public static function deleteAllTags($itemid) { diff --git a/view/theme/frio/templates/photo_view.tpl b/view/theme/frio/templates/photo_view.tpl index cc72a10fa2..939d9f0e98 100644 --- a/view/theme/frio/templates/photo_view.tpl +++ b/view/theme/frio/templates/photo_view.tpl @@ -52,12 +52,12 @@ {{* Tags and mentions *}} {{if $tags}}
{{$tags.title}} - {{foreach $tags.tags as $t}} - - {{$t.name}} - {{if $t.removeurl}} (x) {{/if}} - - {{/foreach}} + {{foreach $tags.tags as $t}} + + {{$t.name}} + {{if $t.removeurl}} (x) {{/if}} + + {{/foreach}}
{{/if}} From 26ed71cc14a9c8a11e659591b0d7cac02cdbdee1 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 13:38:31 +0200 Subject: [PATCH 04/10] Only perform Term::deleteAllTags when needed + not needed redirect --- mod/tagrm.php | 3 --- src/Model/Item.php | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index 4bdaeb32f1..8497bc28a6 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -71,9 +71,6 @@ function update_tags($item_id, $tags){ Item::update(['tag' => $tag_str], ['id' => $item_id]); info(L10n::t('Tag(s) removed') . EOL ); - $a->internalRedirect($_SESSION['photo_return']); - - // NOTREACHED } function tagrm_content(App $a) diff --git a/src/Model/Item.php b/src/Model/Item.php index 9b016295ee..3df2429313 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -896,14 +896,15 @@ class Item extends BaseObject } if (!is_null($tags)) { - Term::deleteAllTags($item['id']); - if ($tags) { Term::insertFromTagFieldByItemId($item['id'], $tags); if (!empty($item['tag'])) { DBA::update('item', ['tag' => ''], ['id' => $item['id']]); } } + else { + Term::deleteAllTags($item['id']); + } } if (!empty($files)) { From e022bac33927ea3469cdadd55bd1e798cbeaeca7 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 19:29:59 +0200 Subject: [PATCH 05/10] Code Standard + renaming deleteAllTags + move its call and add type param --- mod/photos.php | 5 ++--- mod/tagrm.php | 28 ++++++++++++------------ src/Model/Item.php | 11 +++------- src/Model/Term.php | 10 ++++----- view/theme/frio/templates/photo_view.tpl | 2 +- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 65ad9b5d4b..247898ccd3 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1418,9 +1418,8 @@ function photos_content(App $a) $arr = explode(',', $link_item['tag']); // parse tags and add links $tag_arr = []; - foreach ($arr as $t) { - array_push($tag_arr, ['name' => BBCode::convert($t), - 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($t)]); + foreach ($arr as $tag) { + array_push($tag_arr, ['name' => BBCode::convert($tag), 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); } $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { diff --git a/mod/tagrm.php b/mod/tagrm.php index 8497bc28a6..a5288eaf99 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -9,6 +9,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Item; +use Friendica\Model\Term; function tagrm_post(App $a) { @@ -21,10 +22,8 @@ function tagrm_post(App $a) } $tags = []; - if (defaults($_POST, 'tag', '')){ - foreach ($_POST['tag'] as $t){ - array_push($tags, hex2bin(notags(trim($t)))); - } + foreach (defaults($_POST, 'tag', []) as $tag) { + array_push($tags, hex2bin(notags(trim($tag)))); } $item_id = defaults($_POST,'item', 0); @@ -52,23 +51,24 @@ function update_tags($item_id, $tags){ $a->internalRedirect($_SESSION['photo_return']); } - $arr = explode(',', $item['tag']); + $old_tags = explode(',', $item['tag']); - foreach ($tags as $t) { - foreach ($arr as $i => $x) { - if (strcmp($x, $t) == 0) { - unset($arr[$i]); + foreach ($tags as $new_tag) { + foreach ($old_tags as $count => $old_tag) { + if (strcmp($old_tag, $new_tag) == 0) { + unset($old_tags[$count]); break; } } } - $tag_str = implode(',',$arr); - if(empty($tag_str)){ - $tag_str = ''; + $tag_str = implode(',',$old_tags); + if(!empty($tag_str)) { + Item::update(['tag' => $tag_str], ['id' => $item_id]); + } + else { + Term::deleteByItemId($item_id); } - - Item::update(['tag' => $tag_str], ['id' => $item_id]); info(L10n::t('Tag(s) removed') . EOL ); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 3df2429313..77828273bc 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -896,14 +896,9 @@ class Item extends BaseObject } if (!is_null($tags)) { - if ($tags) { - Term::insertFromTagFieldByItemId($item['id'], $tags); - if (!empty($item['tag'])) { - DBA::update('item', ['tag' => ''], ['id' => $item['id']]); - } - } - else { - Term::deleteAllTags($item['id']); + Term::insertFromTagFieldByItemId($item['id'], $tags); + if (!empty($item['tag'])) { + DBA::update('item', ['tag' => ''], ['id' => $item['id']]); } } diff --git a/src/Model/Term.php b/src/Model/Term.php index 75cc100703..f62fced709 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -76,7 +76,7 @@ class Term $message['tag'] = $tags; // Clean up all tags - DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]); + self::deleteByItemId($itemid); if ($message['deleted']) { return; @@ -294,16 +294,16 @@ class Term /** * Delete all tags from an item * @param int itemid - choose from which item the tags will be removed + * @param array type - items type. default is [TERM_HASHTAG, TERM_MENTION] */ - public static function deleteAllTags($itemid) + public static function deleteByItemId($itemid, $type = [TERM_HASHTAG, TERM_MENTION]) { - $message = Item::selectFirst(['id'], ['id' => $itemid]); - if (!DBA::isResult($message)) { + if (empty($itemid)) { return; } // Clean up all tags - DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]); + DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => $type]); } } diff --git a/view/theme/frio/templates/photo_view.tpl b/view/theme/frio/templates/photo_view.tpl index 939d9f0e98..7dc2db901e 100644 --- a/view/theme/frio/templates/photo_view.tpl +++ b/view/theme/frio/templates/photo_view.tpl @@ -55,7 +55,7 @@ {{foreach $tags.tags as $t}} {{$t.name}} - {{if $t.removeurl}} (x) {{/if}} + {{if $t.removeurl}} (X) {{/if}} {{/foreach}} From b03050c339fdc3384d9f2b8f900ed8bd9fd1d258 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 21:18:07 +0200 Subject: [PATCH 06/10] Replace update/delete with Term::insertFramTagFieldByItemId + Code Standards + Wording --- mod/photos.php | 5 +++-- mod/tagrm.php | 13 +++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 247898ccd3..d1bb1af831 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1419,12 +1419,13 @@ function photos_content(App $a) // parse tags and add links $tag_arr = []; foreach ($arr as $tag) { - array_push($tag_arr, ['name' => BBCode::convert($tag), 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); + array_push($tag_arr, ['name' => BBCode::convert($tag), + 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); } $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { $tags += ['removeanyurl' => 'tagrm/' . $link_item['id']]; - $tags += ['removetitle' => L10n::t('[Remove any tag]')]; + $tags += ['removetitle' => L10n::t('[Select tags to remove]')]; } } diff --git a/mod/tagrm.php b/mod/tagrm.php index a5288eaf99..1683bf1d6f 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -29,8 +29,6 @@ function tagrm_post(App $a) $item_id = defaults($_POST,'item', 0); update_tags($item_id, $tags); - info(L10n::t('Tag(s) removed') . EOL ); - $a->internalRedirect($_SESSION['photo_return']); // NOTREACHED @@ -43,12 +41,12 @@ function tagrm_post(App $a) */ function update_tags($item_id, $tags){ if (empty($item_id) || empty($tags)){ - $a->internalRedirect($_SESSION['photo_return']); + return; } $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]); if (!DBA::isResult($item)) { - $a->internalRedirect($_SESSION['photo_return']); + return; } $old_tags = explode(',', $item['tag']); @@ -63,12 +61,7 @@ function update_tags($item_id, $tags){ } $tag_str = implode(',',$old_tags); - if(!empty($tag_str)) { - Item::update(['tag' => $tag_str], ['id' => $item_id]); - } - else { - Term::deleteByItemId($item_id); - } + Term::insertFromTagFieldByItemId($item_id, $tag_str); info(L10n::t('Tag(s) removed') . EOL ); } From ea36f8545767fdd0bfdca6662a8aa9959fe96e73 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Tue, 23 Oct 2018 21:41:55 +0200 Subject: [PATCH 07/10] Code Standard: indent --- mod/photos.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index d1bb1af831..d50dc6fec8 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1419,8 +1419,8 @@ function photos_content(App $a) // parse tags and add links $tag_arr = []; foreach ($arr as $tag) { - array_push($tag_arr, ['name' => BBCode::convert($tag), - 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); + array_push($tag_arr, ['name' => BBCode::convert($tag), + 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); } $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { From 581d1b9c9ef723d5b8f0b4fa5f653c84aaf09f3f Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Thu, 25 Oct 2018 21:49:18 +0200 Subject: [PATCH 08/10] Code Standards: Spaces --- mod/tagrm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index 1683bf1d6f..f92bd856b4 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -63,7 +63,7 @@ function update_tags($item_id, $tags){ $tag_str = implode(',',$old_tags); Term::insertFromTagFieldByItemId($item_id, $tag_str); - info(L10n::t('Tag(s) removed') . EOL ); + info(L10n::t('Tag(s) removed') . EOL); } function tagrm_content(App $a) @@ -75,7 +75,7 @@ function tagrm_content(App $a) // NOTREACHED } - if ($a->argc == 3){ + if ($a->argc == 3) { update_tags($a->argv[1], [hex2bin(notags(trim($a->argv[2])))]); $a->internalRedirect($_SESSION['photo_return']); } From 6bab8f1a43b8c4fe0be5ddb8b2ebd408c7070c0c Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Thu, 25 Oct 2018 21:57:11 +0200 Subject: [PATCH 09/10] Fix ? --- mod/tagrm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index f92bd856b4..6f9cf553a7 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -6,7 +6,6 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Core\L10n; -use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Item; use Friendica\Model\Term; From deed949ff0aa21c134a3bf695b5d81efc1356a5f Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Fri, 26 Oct 2018 00:18:47 +0200 Subject: [PATCH 10/10] Code Standards: var name, spaces, array_push short form --- mod/photos.php | 10 ++++++---- mod/tagrm.php | 14 ++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index d50dc6fec8..b80350221b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1419,13 +1419,15 @@ function photos_content(App $a) // parse tags and add links $tag_arr = []; foreach ($arr as $tag) { - array_push($tag_arr, ['name' => BBCode::convert($tag), - 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]); + $tag_arr[] = [ + 'name' => BBCode::convert($tag), + 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag) + ]; } $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { - $tags += ['removeanyurl' => 'tagrm/' . $link_item['id']]; - $tags += ['removetitle' => L10n::t('[Select tags to remove]')]; + $tags['removeanyurl'] = 'tagrm/' . $link_item['id']; + $tags['removetitle'] = L10n::t('[Select tags to remove]'); } } diff --git a/mod/tagrm.php b/mod/tagrm.php index 6f9cf553a7..2678748de5 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -22,14 +22,14 @@ function tagrm_post(App $a) $tags = []; foreach (defaults($_POST, 'tag', []) as $tag) { - array_push($tags, hex2bin(notags(trim($tag)))); + $tags[] = hex2bin(notags(trim($tag))); } $item_id = defaults($_POST,'item', 0); update_tags($item_id, $tags); + info(L10n::t('Tag(s) removed') . EOL); $a->internalRedirect($_SESSION['photo_return']); - // NOTREACHED } @@ -51,18 +51,16 @@ function update_tags($item_id, $tags){ $old_tags = explode(',', $item['tag']); foreach ($tags as $new_tag) { - foreach ($old_tags as $count => $old_tag) { + foreach ($old_tags as $index => $old_tag) { if (strcmp($old_tag, $new_tag) == 0) { - unset($old_tags[$count]); + unset($old_tags[$index]); break; } } } - $tag_str = implode(',',$old_tags); + $tag_str = implode(',', $old_tags); Term::insertFromTagFieldByItemId($item_id, $tag_str); - - info(L10n::t('Tag(s) removed') . EOL); } function tagrm_content(App $a) @@ -75,7 +73,7 @@ function tagrm_content(App $a) } if ($a->argc == 3) { - update_tags($a->argv[1], [hex2bin(notags(trim($a->argv[2])))]); + update_tags($a->argv[1], [notags(trim(hex2bin($a->argv[2])))]); $a->internalRedirect($_SESSION['photo_return']); }