HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: /home4/cca63905/.trash/wp-content/plugins/tidio-live-chat/src/IntegrationState.php
<?php

namespace TidioLiveChat;

if (!defined('WPINC')) {
    die('File loaded directly. Exiting.');
}

use TidioLiveChat\Sdk\Encryption\Service\OpenSslEncryptionService;

class IntegrationState
{
    const PUBLIC_KEY_OPTION = 'tidio-one-public-key';
    const PRIVATE_KEY_OPTION = 'tidio-one-private-key';
    const ASYNC_LOAD_OPTION = 'tidio-async-load';
    const TIDIO_OAUTH_ACCESS_TOKEN_KEY = 'tidio-access-token';
    const TIDIO_OAUTH_REFRESH_TOKEN_KEY = 'tidio-refresh-token';

    /**
     * @var OpenSslEncryptionService
     */
    private $encryptionService;

    /**
     * @param OpenSslEncryptionService $encryptionService
     */
    public function __construct($encryptionService)
    {
        $this->encryptionService = $encryptionService;
    }

    /**
     * @return string|null
     */
    public function getProjectPublicKey()
    {
        return get_option(self::PUBLIC_KEY_OPTION, null);
    }

    /**
     * @return string|null
     */
    public function getProjectPrivateKey()
    {
        return get_option(self::PRIVATE_KEY_OPTION, null);
    }

    /**
     * @return bool
     */
    public function hasProjectPrivateKey()
    {
        return !empty(get_option(self::PRIVATE_KEY_OPTION));
    }

    /**
     * @return bool
     */
    public function isPluginIntegrated()
    {
        return !empty(get_option(self::PUBLIC_KEY_OPTION));
    }

    /**
     * @return bool
     */
    public function isAsyncLoadingTurnedOn()
    {
        return (bool) get_option(self::ASYNC_LOAD_OPTION);
    }

    public function integrate($projectPublicKey, $accessToken, $refreshToken)
    {
        $encryptedRefreshToken = $this->encryptionService->encrypt($refreshToken);

        update_option(self::PUBLIC_KEY_OPTION, $projectPublicKey);
        update_option(self::TIDIO_OAUTH_ACCESS_TOKEN_KEY, $accessToken);
        update_option(self::TIDIO_OAUTH_REFRESH_TOKEN_KEY, $encryptedRefreshToken);
        update_option(self::ASYNC_LOAD_OPTION, true);
    }

    public function removeIntegration()
    {
        delete_option(self::PUBLIC_KEY_OPTION);
        delete_option(self::TIDIO_OAUTH_ACCESS_TOKEN_KEY);
        delete_option(self::TIDIO_OAUTH_REFRESH_TOKEN_KEY);
        delete_option(self::ASYNC_LOAD_OPTION);
        delete_option(self::PRIVATE_KEY_OPTION);
    }

    public function turnOnAsyncLoading()
    {
        update_option(self::ASYNC_LOAD_OPTION, true);
    }

    public function toggleAsyncLoading()
    {
        update_option(self::ASYNC_LOAD_OPTION, !$this->isAsyncLoadingTurnedOn());
    }
}