]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6028 from annando/issue-5913
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Oct 2018 04:32:16 +0000 (00:32 -0400)
committerGitHub <noreply@github.com>
Fri, 26 Oct 2018 04:32:16 +0000 (00:32 -0400)
Issue 5913: Fix fatal error in "RemoveUser"

doc/Install.md
doc/de/Install.md
mod/photos.php
mod/tagrm.php
src/Model/Item.php
src/Model/Term.php
view/theme/frio/templates/photo_view.tpl

index e6d1d40645a5386e0ef94f2dd218855cd2bc776e..e8a7d509edbf1af3faf5dc0133655a16f33c06c7 100644 (file)
@@ -195,7 +195,7 @@ All options will be saved in the `config/local.ini.php` and are overruling the a
 -      `-b|--phppath <php_path>` The path of the PHP binary (env `FRIENDICA_PHP_PATH`)
 -      `-A|--admin <mail>` The admin email address of Friendica (env `FRIENDICA_ADMIN_MAIL`)
 -      `-T|--tz <timezone>` The timezone of Friendica (env `FRIENDICA_TZ`)
--      `-L|--land <language>` The language of Friendica (env `FRIENDICA_LANG`)
+-      `-L|--lang <language>` The language of Friendica (env `FRIENDICA_LANG`)
 
 Navigate to the main Friendica directory and execute the following command:
 
index 132fbc19041a13fd4227d31df45818c243268dee..21c5513ac443f56493fb2cb595593ca9b5e0005e 100644 (file)
@@ -196,7 +196,7 @@ Alle Optionen werden in `config/local.ini.php` gespeichert und überschreiben et
 -      `-b|--phppath <path>` Der Pfad zur PHP-Datei (env `FRIENDICA_PHP_PATH`)
 -      `-A|--admin <mail>` Die Admin E-Mail Adresse dieses Friendica Knotens (env `FRIENDICA_ADMIN_MAIL`)
 -      `-T|--tz <timezone>` Die Zeitzone von Friendica (env `FRIENDICA_TZ`)
--      `-L|--land <language>` Die Sprache von Friendica (env `FRIENDICA_LANG`)
+-      `-L|--lang <language>` Die Sprache von Friendica (env `FRIENDICA_LANG`)
 
 Gehe in den Friendica-Hauptordner und führe den Kommandozeilen Befehl aus:
 
index 008d59cd9cd23d08dff9b41e7a8ecaf5a3098aab..b80350221bf4cdc93336714fc66b47661ef8d3e5 100644 (file)
@@ -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,17 @@ 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 = '';
-                       foreach ($arr as $t) {
-                               if (strlen($tag_str)) {
-                                       $tag_str .= ', ';
-                               }
-                               $tag_str .= BBCode::convert($t);
+                       $tag_arr = [];
+                       foreach ($arr as $tag) {
+                               $tag_arr[] = [
+                                       'name' => BBCode::convert($tag),
+                                       'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)
+                               ];
                        }
-                       $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('[Select tags to remove]');
                        }
                }
 
index 105cc0b3d55467b867a5f8b1a3081b4cd698fcba..2678748de5831e3e930a4dc45144edc0697beb87 100644 (file)
@@ -6,9 +6,9 @@
 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;
 
 function tagrm_post(App $a)
 {
@@ -20,34 +20,49 @@ 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 = [];
+       foreach (defaults($_POST, 'tag', []) as $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
+}
+
+/**
+ * Updates tags from an item
+ * @param $item_id
+ * @param $tags array
+ */
+function update_tags($item_id, $tags){
+       if (empty($item_id) || empty($tags)){
+               return;
+       }
 
        $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
        if (!DBA::isResult($item)) {
-               $a->internalRedirect($_SESSION['photo_return']);
+               return;
        }
 
-       $arr = explode(',', $item['tag']);
-       for ($x = 0; $x < count($arr); $x ++) {
-               if ($arr[$x] === $tag) {
-                       unset($arr[$x]);
-                       break;
+       $old_tags = explode(',', $item['tag']);
+
+       foreach ($tags as $new_tag) {
+               foreach ($old_tags as $index => $old_tag) {
+                       if (strcmp($old_tag, $new_tag) == 0) {
+                               unset($old_tags[$index]);
+                               break;
+                       }
                }
        }
 
-       $tag_str = implode(',',$arr);
-
-       Item::update(['tag' => $tag_str], ['id' => $item_id]);
-
-       info(L10n::t('Tag removed') . EOL );
-       $a->internalRedirect($_SESSION['photo_return']);
-
-       // NOTREACHED
+       $tag_str = implode(',', $old_tags);
+       Term::insertFromTagFieldByItemId($item_id, $tag_str);
 }
 
-
-
 function tagrm_content(App $a)
 {
        $o = '';
@@ -57,6 +72,11 @@ function tagrm_content(App $a)
                // NOTREACHED
        }
 
+       if ($a->argc == 3) {
+               update_tags($a->argv[1], [notags(trim(hex2bin($a->argv[2])))]);
+               $a->internalRedirect($_SESSION['photo_return']);
+       }
+
        $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
        if (!$item_id) {
                $a->internalRedirect($_SESSION['photo_return']);
@@ -70,7 +90,8 @@ function tagrm_content(App $a)
 
        $arr = explode(',', $item['tag']);
 
-       if (!count($arr)) {
+
+       if (empty($item['tag'])) {
                $a->internalRedirect($_SESSION['photo_return']);
        }
 
@@ -83,7 +104,7 @@ function tagrm_content(App $a)
        $o .= '<ul>';
 
        foreach ($arr as $x) {
-               $o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
+               $o .= '<li><input type="checkbox" name="tag[]" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
        }
 
        $o .= '</ul>';
index a39093d78546303ffd156babc22e2e13fd511845..e7358a776e8412b0a9f2be4c712e43ddb136ae0c 100644 (file)
@@ -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,7 +895,7 @@ class Item extends BaseObject
                                }
                        }
 
-                       if (!empty($tags)) {
+                       if (!is_null($tags)) {
                                Term::insertFromTagFieldByItemId($item['id'], $tags);
                                if (!empty($item['tag'])) {
                                        DBA::update('item', ['tag' => ''], ['id' => $item['id']]);
index 854861ccb589b022609d48000a7b21f0d2ce286c..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;
@@ -290,4 +290,20 @@ class Term
 
                return $return;
        }
+
+       /**
+        * 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 deleteByItemId($itemid, $type = [TERM_HASHTAG, TERM_MENTION])
+       {
+               if (empty($itemid)) {
+                       return;
+               }
+
+               // Clean up all tags
+               DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => $type]);
+
+       }
 }
index e610926d4cbf3550683f54bcca423c1550821a83..7dc2db901e2f7492ed450a69b0b1688aa916c284 100644 (file)
 
                {{* Tags and mentions *}}
                {{if $tags}}
-               <div id="photo-tags">{{$tags.1}}</div>
+               <div id="photo-tags">{{$tags.title}}
+                       {{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}}
+                       </span>
+                       {{/foreach}}
+               </div>
                {{/if}}
 
-               {{if $tags.2}}
+               {{if $tags.removeanyurl}}
                <div id="tag-remove">
-                       <a href="{{$tags.2}}">{{$tags.3}}</a>
+                       <a href="{{$tags.removeanyurl}}">{{$tags.removetitle}}</a>
                </div>
                {{/if}}