View file MMO-Hide-2.3.4/upload/src/addons/MMO/Hide/BbCode/Tag/HideUsers.php

File size: 1.31Kb
<?php

namespace MMO\Hide\BbCode\Tag;

use MMO\Hide\BbCode\AbstractTag;
use XF\Repository\UserRepository;

class HideUsers extends AbstractTag
{
    /**
     * @inheritDoc
     */
    public function render($content, array $tagChildren, $tagOption, array $tag, array $options)
    {
        $canView = false;
        $usernames = \explode(',', $tagOption);
        $matchedUsers = $this->repository(UserRepository::class)
            ->getUsersByNames($usernames, $notFound);
        $userLinks = [];

        if (!empty($matchedUsers))
        {
            foreach ($matchedUsers as $user)
            {
                $userLinks[] = $this->templater->func('username_link', [$user, true]);

                if ($user->user_id == $this->visitor()->user_id)
                {
                    $canView = true;
                }
            }
        }

        $params = [
            'users' => implode(', ', $userLinks)
        ];

        $title = [
            'visible' => $this->getTitleVisible('mh_tag_users', $params),
            'hidden' => $this->getTitleHidden('mh_tag_users', $params)
        ];

        return $this->renderTemplate($content, $title, [
            'canView' => $canView,
            'options' => $options,
            'tag' => $tag['tag']
        ]);
    }
}