]> git.mxchange.org Git - friendica-addons.git/commitdiff
[tumblr] Skip empty tags when saving user-defined tags
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 21 Feb 2025 04:03:27 +0000 (23:03 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 21 Feb 2025 04:03:27 +0000 (23:03 -0500)
- Skip empty tags when fetching them
↪ Empty tags were triggering a Tumblr API error
- Address https://github.com/friendica/friendica/issues/14646#issuecomment-2628090487
- Using log output from https://github.com/friendica/friendica/issues/14646#issuecomment-2665000962

tumblr/tumblr.php

index f2e2d78d8641512242b8ace9e92ee834f6032e91..4415e2de370b6b60440ca7a393cdd803e6fda1f2 100644 (file)
@@ -391,12 +391,17 @@ function tumblr_settings_post(array &$b)
                DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'import',          intval($_POST['tumblr_import']));
 
                $max_tags = DI::config()->get('tumblr', 'max_tags') ?? TUMBLR_DEFAULT_MAXIMUM_TAGS;
-               $tags     = [];
-               foreach (explode(',', $_POST['tags']) as $tag) {
-                       if (count($tags) < $max_tags) {
-                               $tags[] = trim($tag, ' #');
-                       }
-               }
+
+               $tags = array_slice(
+                       array_filter(
+                               array_map(
+                                       function($tag) { return trim($tag, ' #');},
+                                       explode(',', $_POST['tags']) ?: []
+                               )
+                       ),
+                       0,
+                       $max_tags,
+               );
 
                DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'tags', $tags);
        }
@@ -742,6 +747,11 @@ function tumblr_fetch_tags(int $uid, int $last_poll)
        }
 
        foreach (DI::pConfig()->get($uid, 'tumblr', 'tags') ?? [] as $tag) {
+               // Tumblr will return an error for queries on empty tag
+               if (!$tag) {
+                       continue;
+               }
+
                $data = tumblr_get($uid, 'tagged', ['tag' => $tag]);
 
                if (!is_array($data->response)) {