<?php
namespace Claromentis\Gallery;

$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_f784524629d9404cd62" . "ba9e1475d3bc3" => base64_decode("b2JqZWN0X25h" . "bWU="), "n" . "a" . "m" . "e" => base64_decode("bmFtZ" . "Q=="), "_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1zZw" . "=="), "_d91345deaf5ce6430a776cdc17f9b" . "138" => base64_decode("Y29" . "tbW" . "Vud" . "HM="), "_c9a3e038e3" . "e182836a207" . "61c8ab11dcc" => base64_decode("L2ludHJhbmV0L2dhbGxlcnk" . "v"), "u" . "r" . "l" => base64_decode("dXJ" . "s"), "_4be135064c4d55c13e6af60c45" . "cb1fda" => base64_decode("Z2FsbGVyeS5wZXJtaXNzaW9" . "ucw=="), "_e06da3ffba2e84b8e6f" . "94bd2d6ca3c52" => base64_decode("Y3JlYXRlX" . "2ludGVybm" . "FsX2xpbms" . "="), "_911d014" . "6a480bd9" . "a1a71e7a" . "aa11b6be" . "8" => base64_decode("Y29tbW9uLnR5cGUua" . "W1hZ2VfZ2FsbGVyeQ" . "=="), "_e6f08544d6e937ce52c23b" . "8756ec8fb0" => base64_decode("L2ludHJhbmV0L2dhbGxlcnkv" . "dmlld19hbGJ1bS5waHA/YWxi" . "dW1faWQ9"));
use ClaAggregation;
use Claromentis\Comments\CommentableInterface;
use Claromentis\Comments\CommentLocationInterface;
use Claromentis\Comments\CommentsRepository;
use Claromentis\Comments\Model\Comment;
use Claromentis\Comments\Notification\Notification;
use Claromentis\Comments\Rights;
use Claromentis\Comments\SupportedOptions;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Core\Services;
use Image;
use ImageAlbum;




class CommentableImage implements CommentableInterface, CommentLocationInterface
{
    
    
    
    
    private $image_id;
    
    
    
    
    private $image;
    
    
    
    
    private $album;
    private CommentsRepository $comments_repository;
    public function __construct()
    {
        $this->comments_repository = Services::I()->{$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_d91345deaf5ce6430a776cdc17f9" . "b138"]};
    }
    
    
    
    
    
    
    
    
    public function Load($id, $_4a033bdf0ce701c6255d5238633ab2d0 = array())
    {
        $this->image_id = $id;
        $this->image = null;
        $this->album = null;
    }
    
    
    
    
    
    
    
    public function GetAggregationObject()
    {
        if ($this->image === null) {
            $this->image = new Image($this->image_id);
            $this->album = new ImageAlbum($this->image->GetAlbumID());
        }
        return $this->image;
    }
    
    
    
    
    
    
    
    
    public function GetOptions()
    {
        return [SupportedOptions::REPLIES => true, SupportedOptions::LIKES => true, SupportedOptions::ATTACHMENTS => true];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function UserHasPermission(SecurityContext $context, $perms, Comment $comment = null)
    {
        
        
        
        
        $_54faabe694dfa8d05dc6c0827a214f82 = $this->GetAggregationObject();
        $_0bc7588938bfc7dc40d438d105dcdf1c = $this->album;
        global $g_application;
        $_84e255a4ec669726bc592e3153ce97c1 = $g_application[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4be135064c4d55c13" . "e6af60c45cb1fda"]];
        if (!$_0bc7588938bfc7dc40d438d105dcdf1c->UserHasPermission(PERM_VIEW) && !$_84e255a4ec669726bc592e3153ce97c1->CanIManageAlbums()) {
            return false;
        }
        if ($perms != Rights::PERM_VIEW && !$_0bc7588938bfc7dc40d438d105dcdf1c->GetCommentsEnabled()) {
            return false;
        }
        if (($perms & Rights::PERM_EDIT) == Rights::PERM_EDIT || ($perms & Rights::PERM_DELETE) == Rights::PERM_DELETE) {
            if ($comment && !$_0bc7588938bfc7dc40d438d105dcdf1c->UserHasPermission(PERM_EDIT_META) && (int) $comment->user_id !== $context->GetUserId()) {
                return false;
            }
        }
        if ($comment && ($perms & Rights::PERM_DELETE) == Rights::PERM_DELETE && $comment->HasReplies()) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function Notify(Comment $comment, Notification $_0dfb4a13f8c551dff0f061eebc847961)
    {
        
        
        
        
        $_54faabe694dfa8d05dc6c0827a214f82 = $this->GetAggregationObject();
        if ((int) $comment->user_id === (int) $_54faabe694dfa8d05dc6c0827a214f82->GetOwner()) {
            return;
        }
        $_0dfb4a13f8c551dff0f061eebc847961->type = GalleryApplication::IM_TYPE_GALLERY_IMAGE;
        $_0dfb4a13f8c551dff0f061eebc847961->AddRecipients([$_54faabe694dfa8d05dc6c0827a214f82->GetOwner()]);
        $_0dfb4a13f8c551dff0f061eebc847961->AddTemplateValues([$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_f78452462" . "9d9404cd62" . "ba9e1475d3" . "bc3"] => $_54faabe694dfa8d05dc6c0827a214f82->GetTitle()]);
        $_0dfb4a13f8c551dff0f061eebc847961->Send();
    }
    public function GetBreadcrumbs(int $object_id)
    {
        $_54faabe694dfa8d05dc6c0827a214f82 = new Image($object_id);
        $_0bc7588938bfc7dc40d438d105dcdf1c = new ImageAlbum($_54faabe694dfa8d05dc6c0827a214f82->GetAlbumId());
        return [[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["nam" . "e"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_0c5123aa744f" . "69bbc0e8b3ea2" . "f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_911d0146" . "a480bd9a1" . "a71e7aaa1" . "1b6be8"]), $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["ur" . "l"] => $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_e06da3ffba" . "2e84b8e6f94" . "bd2d6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_c9a3e038e3e182836a20761" . "c8ab11dcc"])], [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["nam" . "e"] => $_0bc7588938bfc7dc40d438d105dcdf1c->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["u" . "r" . "l"] => $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_e06da3ffba2" . "e84b8e6f94bd" . "2d6ca3c52"]($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e6f08544d6e9" . "37ce52c23b875" . "6ec8fb0"] . $_54faabe694dfa8d05dc6c0827a214f82->GetAlbumId())], [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["n" . "a" . "m" . "e"] => $_54faabe694dfa8d05dc6c0827a214f82->GetTitle(), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["ur" . "l"] => $_54faabe694dfa8d05dc6c0827a214f82->GetUrl()]];
    }
    public function ShouldShowComments() : bool
    {
        return $this->comments_repository->GetCommentsCount($this) > 0 || $this->album->GetCommentsEnabled();
    }
}