HEX
Server: nginx/1.20.1
System: Linux VM-0-8-centos 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64
User: www (1000)
PHP: 7.3.29
Disabled: passthru,system,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,popepassthru,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.ycfawu.com/wp-content/plugins/tidio-live-chat/src/Admin/IframeSetup.php
<?php

namespace TidioLiveChat\Admin;

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

use Exception;
use TidioLiveChat\IntegrationState;
use TidioLiveChat\Config;
use TidioLiveChat\WooCommerceSdk\WooCommerceIntegrationService;

class IframeSetup
{
    /**
     * @var IntegrationState
     */
    private $integrationState;
    /**
     * @var WooCommerceIntegrationService
     */
    private $wooCommerceIntegrationService;

    /**
     * @param IntegrationState $integrationState
     */
    public function __construct($integrationState, $wooCommerceIntegrationService)
    {
        $this->integrationState = $integrationState;
        $this->wooCommerceIntegrationService = $wooCommerceIntegrationService;
    }

    /**
     * @return string
     */
    public function prepareAuthenticationIframeUrl()
    {
        $userId = get_current_user_id();
        $userName = get_user_meta($userId, 'first_name', true);

        $queryParams = array_merge(
            [
                'pluginUrl' => AdminRouting::getEndpointForIntegrateProjectAction(),
                'name' => $userName,
                'refId' => $this->readRefIdFromFile()
            ],
            $this->getDefaultIframeQueryParams()
        );

        $iframeBaseUrl = Config::getPanelUrl() . '/register-platforms';
        return sprintf('%s?%s', $iframeBaseUrl, http_build_query($queryParams));
    }

    /**
     * @return string
     */
    public function prepareIntegrationSuccessIframeUrl()
    {
        $queryParams = array_merge(
            [
                'panelUrl' => $this->getPanelRedirectUrl(),
                'reintegrationRoute' => $this->prepareReintegrationIframeRoute()
            ],
            $this->getDefaultIframeQueryParams(),
            $this->wooCommerceIntegrationService->getIntegrationData()->toIframeData()
        );

        $iframeBaseUrl = Config::getPanelUrl() . '/integration-success';
        return sprintf('%s?%s', $iframeBaseUrl, http_build_query($queryParams));
    }

    /**
     * @return string
     */
    private function prepareReintegrationIframeRoute()
    {
        $queryParams = array_merge(
            [
                'pluginUrl' => AdminRouting::getEndpointForIntegrateProjectAction()
            ],
            $this->getDefaultIframeQueryParams()
        );

        return sprintf('/login-platforms?%s', http_build_query($queryParams));
    }

    /**
     * @return array<string, string>
     */
    private function getDefaultIframeQueryParams()
    {
        $userId = get_current_user_id();
        $localeCode = get_user_locale($userId);

        return [
            'siteUrl' => get_home_url(),
            'localeCode' => $localeCode,
            'language' => substr($localeCode, 0, 2),
            'utm_source' => 'platform',
            'utm_medium' => 'wordpress',
        ];
    }

    /**
     * @return string|null
     */
    private function readRefIdFromFile() {
        try {
            $loadedRefIdFromFile = @file_get_contents(AFFILIATE_CONFIG_FILE_PATH);
            return trim($loadedRefIdFromFile);
        } catch (Exception $e) {
            return null;
        }
    }

    /**
     * @return string
     */
    private function getPanelRedirectUrl()
    {
        $queryParams = [
            'utm_source' => 'platform',
            'utm_medium' => 'wordpress'
        ];
        if ($this->integrationState->hasProjectPrivateKey()) {
            $queryParams['privateKey'] = $this->integrationState->getProjectPrivateKey();
            return sprintf('%s/external-access?%s', Config::getPanelUrl(), http_build_query($queryParams));
        }

        return sprintf('%s?%s', Config::getPanelUrl(), http_build_query($queryParams));
    }
}