]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Widget/TagCloud.php
Merge pull request #8036 from nupplaphil/task/redundant_system_call
[friendica.git] / src / Content / Widget / TagCloud.php
index e1ce921c04a10342e710ce4799dd7666807f50e1..15ed41a35cfa73196710445c800572cfbb9ef4dc 100644 (file)
@@ -8,10 +8,9 @@ namespace Friendica\Content\Widget;
 
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Item;
-use Friendica\Util\Security;
 
 /**
  * TagCloud widget
@@ -39,8 +38,9 @@ class TagCloud
                $r = self::tagadelic($uid, $count, $owner_id, $flags, $type);
                if (count($r)) {
                        $contact = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
-                       $url = System::removedBaseUrl($contact['url']);
+                       $url = DI::baseUrl()->remove($contact['url']);
 
+                       $tags = [];
                        foreach ($r as $rr) {
                                $tag['level'] = $rr[2];
                                $tag['url'] = $url . '?tag=' . urlencode($rr[0]);
@@ -49,7 +49,7 @@ class TagCloud
                                $tags[] = $tag;
                        }
 
-                       $tpl = Renderer::getMarkupTemplate('tagblock_widget.tpl');
+                       $tpl = Renderer::getMarkupTemplate('widget/tagcloud.tpl');
                        $o = Renderer::replaceMacros($tpl, [
                                '$title' => L10n::t('Tags'),
                                '$tags' => $tags
@@ -89,7 +89,7 @@ class TagCloud
                }
 
                // Fetch tags
-               $r = DBA::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term`
+               $tag_stmt = DBA::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term`
                        LEFT JOIN `item` ON `term`.`oid` = `item`.`id`
                        WHERE `term`.`uid` = ? AND `term`.`type` = ?
                        AND `term`.`otype` = ?
@@ -100,10 +100,12 @@ class TagCloud
                        $type,
                        TERM_OBJ_POST
                );
-               if (!DBA::isResult($r)) {
+               if (!DBA::isResult($tag_stmt)) {
                        return [];
                }
 
+               $r = DBA::toArray($tag_stmt);
+
                return self::tagCalc($r);
        }
 
@@ -114,7 +116,7 @@ class TagCloud
         * @param array $arr Array of tags/terms with tag/term name and total count of use.
         * @return array     Alphabetical sorted array of used tags/terms of an user.
         */
-       private static function tagCalc($arr)
+       private static function tagCalc(array $arr)
        {
                $tags = [];
                $min = 1e9;