]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Widget.php
Show only the user's categories on their profile
[friendica.git] / src / Content / Widget.php
index 3f97e9f259e50a4c37d6fcef472f755884cfce64..86339928702dadadd879f02e1dbef365d6785d8d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -22,7 +22,7 @@
 namespace Friendica\Content;
 
 use Friendica\Core\Addon;
-use Friendica\Core\Cache\Duration;
+use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
@@ -63,7 +63,7 @@ class Widget
 
                if (DI::config()->get('system', 'invitation_only')) {
                        $x = intval(DI::pConfig()->get(local_user(), 'system', 'invites_remaining'));
-                       if ($x || is_site_admin()) {
+                       if ($x || DI::app()->isSiteAdmin()) {
                                DI::page()['aside'] .= '<div class="side-link widget" id="side-invite-remain">'
                                        . DI::l10n()->tt('%d invitation available', '%d invitations available', $x)
                                        . '</div>';
@@ -259,12 +259,10 @@ class Widget
                }
 
                $networks = self::unavailableNetworks();
-               $extra_sql = " AND NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")";
-               $sql_values = array_merge([local_user()], $networks);
+               $query = "`uid` = ? AND NOT `deleted` AND `network` != '' AND NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")";
+               $condition = array_merge([$query], array_merge([local_user()], $networks));
 
-               $r = DBA::p("SELECT `network` FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql GROUP BY `network` ORDER BY `network`",
-                       $sql_values
-               );
+               $r = DBA::select('contact', ['network'], $condition, ['group_by' => ['network'], 'order' => ['network']]);
 
                $nets = array();
                while ($rr = DBA::fetch($r)) {
@@ -320,23 +318,20 @@ class Widget
        /**
         * Return categories widget
         *
-        * @param string $baseurl  baseurl
-        * @param string $selected optional, default empty
+        * @param int    $uid      Id of the user owning the categories
+        * @param string $baseurl  Base page URL
+        * @param string $selected Selected category
         * @return string|void
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function categories($baseurl, $selected = '')
+       public static function categories(int $uid, string $baseurl, string $selected = '')
        {
-               $a = DI::app();
-
-               $uid = intval($a->getProfileOwner());
-
                if (!Feature::isEnabled($uid, 'categories')) {
                        return '';
                }
 
                $terms = array();
-               foreach (Post\Category::getArray(local_user(), Post\Category::CATEGORY) as $savedFolderName) {
+               foreach (Post\Category::getArray($uid, Post\Category::CATEGORY) as $savedFolderName) {
                        $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
                }