1
0
Fork 0

Code Standard + renaming deleteAllTags + move its call and add type param

This commit is contained in:
Jonny Tischbein 2018-10-23 19:29:59 +02:00
commit e022bac339
5 changed files with 25 additions and 31 deletions

View file

@ -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') {

View file

@ -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 );
}