Вход Регистрация
Файл: system/src/System/View/Extension/Avatar.php
Строк: 70
<?php

/**
 * This file is part of JohnCMS Content Management System.
 *
 * @copyright JohnCMS Community
 * @license   https://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link      https://johncms.com JohnCMS Project
 */

declare(strict_types=1);

namespace 
JohncmsSystemViewExtension;

use 
MobicmsRenderEngine;
use 
MobicmsRenderExtensionInterface;
use 
PsrContainerContainerInterface;

class 
Avatar implements ExtensionInterface
{
    
/** @var array */
    
private $config;

    
/** @var Assets */
    
private $assets;

    public function 
__invoke(ContainerInterface $container): self
    
{
        
$this->config $container->get('config')['johncms'];
        
$this->assets $container->get(Assets::class);
        return 
$this;
    }

    public function 
register(Engine $engine): void
    
{
        
$engine->registerFunction('avatar', [$this'getUserAvatar']);
    }

    public function 
getUserAvatar(int $userId): string
    
{
        if (
$userId 0) {
            
$avatar UPLOAD_PATH 'users/avatar/' $userId '.png';
            if (
file_exists($avatar)) {
                return 
$this->assets->urlFromPath($avatarROOT_PATH$this->config['homeurl']) .
                    
'?v=' filemtime($avatar);
            }
        }

        return 
$this->assets->url('icons/user.svg');
    }
}
Онлайн: 1
Реклама