Your IP : 216.73.216.224


Current Path : /var/www/html/plugins/kunena/comprofiler/src/Helper/
Upload File :
Current File : /var/www/html/plugins/kunena/comprofiler/src/Helper/KunenaProfileComprofiler.php

<?php

/**
 * Kunena Plugin
 *
 * @package         Kunena.Plugins
 * @subpackage      Comprofiler
 *
 * @copyright       Copyright (C) 2008 - 2026 Kunena Team. All rights reserved.
 * @license         https://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link            https://www.kunena.org
 **/

namespace Kunena\Forum\Plugin\Kunena\Comprofiler\Helper;

\defined('_JEXEC') or die();

use CB\Database\Table\UserTable;
use Joomla\CMS\Factory;
use Kunena\Forum\Libraries\Error\KunenaError;
use Kunena\Forum\Libraries\Factory\KunenaFactory;
use Kunena\Forum\Libraries\Integration\KunenaProfile;
use Kunena\Forum\Libraries\Layout\KunenaLayout;
use Kunena\Forum\Libraries\User\KunenaUser;
use Joomla\Registry\Registry;

/**
 * Class KunenaProfileComprofiler
 *
 * @since   Kunena 5.0
 */
class KunenaProfileComprofiler extends KunenaProfile
{
    /**
     * @param   Registry  $params  params
     *
     * @since   Kunena 6.0
     */
    public function __construct(Registry $params)
    {
        $this->params = $params;
    }

    /**
     * @param   string  $event   event
     * @param   array  $params  params
     *
     * @return  void
     *
     * @throws  \Exception
     *
     * @since   Kunena 5.0
     */
    public static function trigger(string $event, array $params): void
    {
        KunenaIntegrationComprofiler::trigger($event, $params);
    }

    /**
     * @return  void
     *
     * @throws  \Exception
     *
     * @since   Kunena 5.0
     */
    public function open(): void
    {
        KunenaIntegrationComprofiler::open();
    }

    /**
     * @return  void
     *
     * @throws  \Exception
     *
     * @since   Kunena 5.0
     */
    public function close(): void
    {
        KunenaIntegrationComprofiler::close();
    }

    /**
     * Get the URL for userlist from CB
     *
     * @param   string  $action  action
     * @param   bool    $xhtml   xhtml
     *
     * @return string
     *
     * @since   Kunena 5.0
     * @throws \Exception
     */
    public function getUserListURL(string $action = '', bool $xhtml = true): string
    {
        global $_CB_framework;

        $config = KunenaFactory::getConfig();
        $my     = Factory::getApplication()->getIdentity();

        if ($config->userlistAllowed == 0 && $my->id == 0) {
            return false;
        }

        return $_CB_framework->userProfilesListUrl(null, $xhtml);
    }

    /**
     * Get the profile URL from CB
     *
     * @param   int     $userid     userid
     * @param   string  $task       task
     * @param   bool    $xhtml      xhtml
     * @param   string  $avatarTab  avatarTab
     *
     * @return  string|false
     * @since   Kunena 5.0
     * @throws  \Exception
     */
    public function getProfileURL(int $userid, $task = '', bool $xhtml = true, string $avatarTab = ''): string|false
    {
        global $_CB_framework;

        $user = KunenaFactory::getUser($userid);

        if (! $user->exists()) {
            return false;
        }

        if ($task === 'edit') {
            return $_CB_framework->userProfileEditUrl(null, $xhtml);
        }

        return $_CB_framework->userProfileUrl($user->userid, $xhtml);
    }

    /**
     * @param   KunenaLayout  $view    view
     * @param   Registry      $params  params
     *
     * @return  string
     *
     * @since   Kunena 5.0
     */
    public function showProfile(KunenaLayout $view, Registry $params): string
    {
        global $_PLUGINS;

        $_PLUGINS->loadPluginGroup('user');

        return implode(
            ' ',
            $_PLUGINS->trigger(
                'forumSideProfile',
                [
                    'kunena',
                    $view,
                    $view->profile->userid,
                    ['config' => &$view->config, 'userprofile' => &$view->profile, 'params' => &$params],
                ]
            )
        );
    }

    /**
     * @param   int  $limit  limit
     *
     * @return  array
     *
     * @throws  \Exception
     *
     * @since   Kunena 5.0
     */
    public function getTopHits($limit = 0): array
    {
        $db    = Factory::getContainer()->get('DatabaseDriver');
        $query = $db->createQuery();
        $query->select('cu.user_id AS id, cu.hits AS count');
        $query->from($db->quoteName('#__comprofiler', 'cu'));
        $query->innerJoin($db->quoteName('#__users', 'u') . ' ON u.id = cu.user_id');
        $query->where('cu.hits > 0');
        $query->order('cu.hits DESC');
        $query->setLimit($limit);
        $db->setQuery($query);

        try {
            $top = (array) $db->loadObjectList();
        } catch (\RuntimeException $e) {
            KunenaError::displayDatabaseError($e);
        }

        return $top;
    }

    /**
     * @param   int   $userid  userid
     * @param   bool  $xhtml   xhtml
     *
     * @return  boolean
     *
     * @since   Kunena 5.0
     */
    public function getEditProfileURL(int $userid, bool $xhtml = true): string
    {
        global $_CB_framework;

        return $_CB_framework->userProfileEditUrl(null, $xhtml);
    }

    /**
     * Return name or username of user with community builder settings
     *
     * @param   KunenaUser  $user         user
     * @param   string      $visitorname  name
     * @param   bool        $escape       escape
     *
     * @return string
     *
     * @since Kunena 5.2
     */
    public function getProfileName(KunenaUser $user, string $visitorname = '', bool $escape = true): string
    {
        if ($user->exists()) {
            return \CBuser::getUserDataInstance($user->userid)->getFormattedName();
        }

        if (! $visitorname) {
            $guestUser = new UserTable();

            $guestUser->set('name', $user->name);
            $guestUser->set('username', $user->username);

            return $guestUser->getFormattedName();
        }

        return $visitorname;
    }
}