<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] ?: array()) + array("_2a5789b3d67b8cd24b7372ffe23" . "9c928" => base64_decode("bW" . "Q1"), "_49a769d3201e" . "b110ac3f8366e" . "284ef7b" => base64_decode("aHR0cHM6Ly93d3cuZ3" . "JhdmF0YXIuY29tL2F2" . "YXRhci8="), "_8288bdf6cef725fd254d3ffa338a" . "8ceb" => base64_decode("L3Blb3BsZ" . "S8="), "_318e4aa98" . "2e1b529017" . "493d685da0" . "5f1" => base64_decode("L3Blb3BsZS91c2Vy" . "Lw=="), "_d44493b5db200585eb7" . "5d147e32d2824" => base64_decode("LmpwZw" . "=="), "_680cc2b" . "8220e94c" . "8c32b8bc" . "7c65519b" . "4" => base64_decode("aXNfaW5" . "0"), "_3d377e2d653107298125aca92a" . "d3b596" => base64_decode("P" . "2" . "Q" . "9"), "_0196b11df55" . "4da5aff4e8f1" . "291153487" => base64_decode("SW52YWxpZCB1c2VyIG" . "9iamVjdCBvciBJRA=="), "_9db7d4f61" . "935744f77b" . "b41a5d83fb" . "18a" => base64_decode("SW52YWxpZCBQZW9wb" . "GUgZW50aXR5IG9yIE" . "lE"), "_62d701c3c53" . "404f06345eb3" . "5720a47b4" => base64_decode("aXNfbnVtZXJpYw=" . "="), "_7e4598ce2b21a2e186ca857" . "7e79d917b" => base64_decode("X2xhcmdlLmpwZ" . "w=="), "_cf88fa10861ab4dc5c0be9" . "bb52fa1e1f" => base64_decode("Y2ZnX21pc3NpbmdfdXNlcl" . "9hdmF0YXI="), "_52bf6fac6d6d723bb1ba0de109f2" . "7356" => base64_decode("L2ludHJhbmV0L3Blb3BsZS9saXN0cGVvcGxl" . "LnBocD9ub2FjY2Vzcz0x"), "_bb7c9b3c20375776" . "72691b81a34ee7eb" => base64_decode("L2xvZ" . "29zLw" . "=="), "_5e30c4717ced36cff9e93" . "e19a5c576cc" => base64_decode("aXNfc3Rya" . "W5n"), "_8fbcfbba22bc6b64aa915" . "086ed5c37e8" => base64_decode("Jn" . "M9"));
use Claromentis\Core\CDN\CDNInterface;
use Claromentis\Core\CDN\CDNSystemException;
use Claromentis\Core\Config\Config;
use Claromentis\Core\HashId\Hasher;
use Claromentis\Core\Http\HttpUtil;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Core\Services;
use Claromentis\People\Config\ConfigOptions;
use Claromentis\People\Entity\Extranet;
use Claromentis\People\Entity\Group;
use Claromentis\People\Entity\Role;
use Claromentis\People\Entity\User;
use Claromentis\People\Repository\UserRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use UnexpectedValueException;






class UrlGenerator
{
    const NO_PHOTO_URL = '/intranet/people/images/no_photo.jpg';
    
    
    
    
    protected $url_generator;
    
    
    
    
    protected $cdn;
    
    
    
    
    protected $http_util;
    
    
    
    
    protected $people_acl;
    
    
    
    
    protected $hashid;
    
    
    
    
    protected $user_repository;
    
    
    
    
    protected $gravatar_source;
    
    
    
    
    
    
    
    
    
    
    
    public function __construct(UrlGeneratorInterface $url_generator, CDNInterface $_fee64623e267830531765c6712d0f041, HttpUtil $_019f644d80568a97cf247afb364302a5, PeopleAcl $_3d3cf5257abd66970c2706086e13633d, Hasher $hashid, UserRepository $_eeeeb0d673b7b0fd0bdca58b5541c3e0, Config $config)
    {
        $this->url_generator = $url_generator;
        $this->cdn = $_fee64623e267830531765c6712d0f041;
        $this->http_util = $_019f644d80568a97cf247afb364302a5;
        $this->people_acl = $_3d3cf5257abd66970c2706086e13633d;
        $this->hashid = $hashid;
        $this->user_repository = $_eeeeb0d673b7b0fd0bdca58b5541c3e0;
        $this->gravatar_source = $config[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_cf88fa108" . "61ab4dc5c0" . "be9bb52fa1" . "e1f"]];
    }
    
    
    
    
    
    
    
    
    
    public function getUserPhotoUrl($_24e0e36600d6af77406a44bb618a6253, SecurityContext $context = null)
    {
        $context = $context ?? Services::I()->{SecurityContext::class};
        if (!$this->people_acl->CanViewUser($context, $_24e0e36600d6af77406a44bb618a6253)) {
            return self::NO_PHOTO_URL;
        }
        $id = $this->getId($_24e0e36600d6af77406a44bb618a6253);
        if ($this->cdn->Exists($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_8288bdf6cef725fd254d" . "3ffa338a8ceb"] . $id . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_d44493b5db200585eb75d147e32d28" . "24"])) {
            return $this->cdn->GetUrl($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8288bdf6cef725fd254d3ffa33" . "8a8ceb"] . $id . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_d44493b5d" . "b200585eb7" . "5d147e32d2" . "824"]);
        }
        return $this->getGravatarUrl($_24e0e36600d6af77406a44bb618a6253, 160);
    }
    
    
    
    
    
    
    
    
    
    public function getLargeUserPhotoUrl($_24e0e36600d6af77406a44bb618a6253, SecurityContext $context = null)
    {
        $context = $context ?? Services::I()->{SecurityContext::class};
        if (!$this->people_acl->CanViewUser($context, $_24e0e36600d6af77406a44bb618a6253)) {
            return self::NO_PHOTO_URL;
        }
        $id = $this->getId($_24e0e36600d6af77406a44bb618a6253);
        if ($this->cdn->Exists($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_8288bdf6ce" . "f725fd254d3" . "ffa338a8ceb"] . $id . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_7e4598ce2b21a2e186ca8577e7" . "9d917b"])) {
            return $this->cdn->GetUrl($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8288bdf6cef725fd254d3ffa" . "338a8ceb"] . $id . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_7e4598c" . "e2b21a2e" . "186ca857" . "7e79d917" . "b"]);
        }
        return $this->getGravatarUrl($_24e0e36600d6af77406a44bb618a6253, 630);
    }
    
    
    
    
    
    
    public function getExtranetLogoUrl(Extranet $_9a2ef4ae6a5745ffe5fac33c88a222fa, SecurityContext $context = null)
    {
        if (!$_9a2ef4ae6a5745ffe5fac33c88a222fa->logo_file) {
            return null;
        }
        try {
            $url = $this->cdn->GetUrl($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_bb7c9b3c2037577" . "672691b81a34ee7e" . "b"] . $_9a2ef4ae6a5745ffe5fac33c88a222fa->logo_file);
        } catch (CDNSystemException $exception) {
            
            
            $url = null;
        }
        if ($url === null) {
            return $url;
        }
        return $this->http_util->CreateInternalLink($url);
    }
    
    
    
    
    
    
    
    
    public function getUserProfileUrl($_24e0e36600d6af77406a44bb618a6253, SecurityContext $context = null)
    {
        $context = $context ?? Services::I()->{SecurityContext::class};
        $user_id = $this->getId($_24e0e36600d6af77406a44bb618a6253);
        if (!$user_id || $context && !$this->people_acl->CanViewUser($context, $_24e0e36600d6af77406a44bb618a6253)) {
            return $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_52bf6fac6d6d723bb1ba0de1" . "09f27356"];
        }
        $_26f03caed539abbac5182a268264a5d8 = $this->hashid->Encode($user_id);
        $url = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_318e4aa982e1b529017493" . "d685da05f1"] . $_26f03caed539abbac5182a268264a5d8;
        return $url;
    }
    
    
    
    
    
    
    
    protected function getId($value)
    {
        if ($value instanceof User || $value instanceof Group || $value instanceof Role || $value instanceof Extranet) {
            return $value->id;
        }
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_680cc2b822" . "0e94c8c32b8" . "bc7c65519b4"]($value) || $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_5e30c4717ced36cff9e93e19" . "a5c576cc"]($value) && $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_62d701c3c53404f" . "06345eb35720a47b" . "4"]($value)) {
            return $value;
        }
        throw new UnexpectedValueException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_9db7d4f61935744f77bb41a5d83fb1" . "8a"]);
    }
    
    
    
    
    
    protected function getUser($_24e0e36600d6af77406a44bb618a6253) : ?User
    {
        if ($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_62d701c3c53404f0" . "6345eb35720a47b4"]($_24e0e36600d6af77406a44bb618a6253)) {
            return $this->user_repository->find($_24e0e36600d6af77406a44bb618a6253);
        }
        if ($_24e0e36600d6af77406a44bb618a6253 instanceof User) {
            return $_24e0e36600d6af77406a44bb618a6253;
        }
        throw new UnexpectedValueException($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0196b11df554da5aff4e8f1" . "291153487"]);
    }
    
    
    
    
    
    
    
    
    protected function getGravatarUrl($_24e0e36600d6af77406a44bb618a6253, int $size)
    {
        $_24e0e36600d6af77406a44bb618a6253 = $this->getUser($_24e0e36600d6af77406a44bb618a6253);
        if (!$_24e0e36600d6af77406a44bb618a6253 || $this->gravatar_source === ConfigOptions::AVATAR_SOURCE_DEFAULT) {
            return self::NO_PHOTO_URL;
        }
        $_72a7209efcd9c803cef80753f412d5cd = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_2a5789b3d67b8cd24b7372f" . "fe239c928"]($_24e0e36600d6af77406a44bb618a6253->email);
        return $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_49a769d" . "3201eb11" . "0ac3f836" . "6e284ef7" . "b"] . $_72a7209efcd9c803cef80753f412d5cd . $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_3d377e2d65310729812" . "5aca92ad3b596"] . $this->gravatar_source . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_8fbcfbba22bc6b64aa915086ed5c3" . "7e8"] . $size;
    }
}