]> git.mxchange.org Git - friendica.git/commitdiff
Code Standard + renaming deleteAllTags + move its call and add type param
authorJonny Tischbein <jonny_tischbein@systemli.org>
Tue, 23 Oct 2018 17:29:59 +0000 (19:29 +0200)
committerJonny Tischbein <jonny_tischbein@systemli.org>
Thu, 25 Oct 2018 19:47:10 +0000 (21:47 +0200)
mod/photos.php
mod/tagrm.php
src/Model/Item.php
src/Model/Term.php
view/theme/frio/templates/photo_view.tpl

index 65ad9b5d4b8658c67a46c63b0bdcfbe0e98b1ba2..247898ccd30e3e0b618740b260eed71e22867a22 100644 (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') {
index 8497bc28a6714ff1e1926cf91e56c1058d1f2986..a5288eaf99b2715f204a09db48b6e6c7e9e5f03c 100644 (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 );
 }
index 3df24293131d7e210420e68a1778aab067cae7df..77828273bc7f27b159665194ad97ccdeb147c69d 100644 (file)
@@ -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']]);
                                }
                        }
 
index 75cc100703c628f51a2c689b06ba97567a84b356..f62fced70904c81dffe384b6fe49c720e37c60bf 100644 (file)
@@ -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]);
 
        }
 }
index 939d9f0e98ad82ccf46df137c1f1813af5f94932..7dc2db901e2f7492ed450a69b0b1688aa916c284 100644 (file)
@@ -55,7 +55,7 @@
                        {{foreach $tags.tags as $t}}
                        <span class="category label btn-success sm">
                                <span class="p-category">{{$t.name}}</span>
-                               {{if $t.removeurl}} (<a href="{{$t.removeurl}}">x</a>) {{/if}}
+                               {{if $t.removeurl}} <a href="{{$t.removeurl}}">(X)</a> {{/if}}
                        </span>
                        {{/foreach}}
                </div>