@param string $submitUrl
@param array  $response
@param string $site

@return array
508106
protected static function executeCurl($submitUrl, array &$response, $site)
    {
        $ch = \curl_init();
        \curl_setopt($ch, CURLOPT_URL, $submitUrl);
        \curl_setopt($ch, CURLOPT_HEADER, true);
        \curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        \curl_exec($ch);

        $response[$site] = ('' === \curl_error($ch));
        \curl_close($ch);

        return $response;
    }
381694
public function renderSiteUrl($site, $path = null, array $options = [], $ignoreSso = false, $dropDestination = true)
    {
        return $this->siteManager->getUrlGenerator()->generateUrl($site, $path, $options, $ignoreSso, $dropDestination);
    }
1044818
public function createPages(
        SiteEntity $site,
        $pagesData,
        $publishPage = false,
        $doFlush = false
    ) {
        $results = [];

        foreach ($pagesData as $name => $pageData) {
            $results[] = $this->createPage(
                $site,
                $pageData,
                $publishPage,
                $doFlush
            );
        }

        return $results;
    }
429520
protected function parseGetPosts($response, $indexAttribute = null, $existsAttributes = [], $postAttributes = []) {

		$posts = $indexAttribute === null ? $response : ArrayHelper::getValue($response, $indexAttribute);

		if (empty($posts)) {
			return null;
		}

		$list = [];
		foreach ($posts as $post) {
			if ($this->isArrayHasKeys($post, $existsAttributes)) {

				$time_created = ArrayHelper::getValue($post, $postAttributes['time_created']);

				array_push($list, [
					'service_id_author' => ArrayHelper::getValue($post, $postAttributes['service_id_author']),
					'service_id_post' => ArrayHelper::getValue($post, $postAttributes['service_id_post']),
					'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
					'content' => ArrayHelper::getValue($post, $postAttributes['content']),
				]);
			}
		}

		return $list;
	}
870616
protected function getParameters(RequestInterface $request, ResponseInterface $response = null)
    {
        $params = [];
        $result = '';

        $keys = array_intersect($this->context, $this->availableParameters);

        foreach ($keys as $key) {
            switch ($key) {
                case 'method':
                    $result = $request->getMethod();
                    break;
                case 'url':
                    $result = $request->getUri()->__toString();
                    break;
                case 'request_version':
                    $result = $request->getProtocolVersion();
                    break;
                case 'response_version':
                    $result = $response ? $response->getProtocolVersion() : 'NULL';
                    break;
                case 'host':
                    $result = $request->getUri()->getHost();
                    break;
                case 'hostname':
                    $result = gethostname();
                    break;
                case 'status_code':
                    $result = $response ? $response->getStatusCode() : 'NULL';
                    break;
                case 'phrase':
                    $result = $response ? $response->getReasonPhrase() : 'NULL';
                    break;
            }

            $params[$key] = (string) $result ?: '';
        }

        return $params;
    }
534125
function http($url, $method, $postfields=null, $headers=array())
    {
        $this->http_info = array();
        $ci = curl_init();
        /* Curl settings */
        curl_setopt($ci, CURLOPT_USERAGENT, self::USER_AGENT);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
        curl_setopt($ci, CURLOPT_TIMEOUT, self::REQUEST_TIMEOUT);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);

        // Set request headers if any
        if (is_array($headers) && !empty($headers)){
            $this->http_request_headers = $headers;
            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
        }

        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, self::SSL_VERIFY_PEER);
        curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
        curl_setopt($ci, CURLOPT_HEADER, false);

        // Make sure the post fields are string
        if (is_array($postfields) && !empty($postfields)) {
            $postfields = http_build_query($postfields);
        }

        switch ($method) {
            case 'POST':
                curl_setopt($ci, CURLOPT_POST, true);
                if (!empty($postfields)) {
                    $this->http_post = $postfields;
                    curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                }
                break;
            case 'DELETE':
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
                if (!empty($postfields)) {
                    $url = "{$url}?{$postfields}";
                }
        }

        curl_setopt($ci, CURLOPT_URL, $url);
        $response = curl_exec($ci);
        $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
        $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
        $this->http_url = $url;
        curl_close($ci);

        return $response;
    }
338179
protected function parsePublishPost($response, $indexAttribute = null, $postAttributes = []) {
		if (ArrayHelper::getValue($response, $indexAttribute)) {
			$time_created = ArrayHelper::getValue($response, $postAttributes['time_created']);

			return [
				'service_id_author' => ArrayHelper::getValue($response, $postAttributes['service_id_author']),
				'service_id_post' => ArrayHelper::getValue($response, $postAttributes['service_id_post']),
				'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
			];
		} else {
			return [];
		}

	}
960347
protected function getRefreshUri(RequestInterface $request, ResponseInterface $response)
    {
        if (preg_match(static::REFRESH_EXPRESSION, $response->getHeaderLine('Refresh'), $matches)) {
            return new Uri($matches[1]);
        }

        return $this->solveJavascriptChallenge($request, $response);
    }
48627
public function getData(
        Site $site,
        $pageName,
        $pageType = PageTypes::NORMAL,
        $revisionId = null
    ) {
        $pageData = $this->getNew();
        $pageData->setSite($site);
        $pageData->setRequestedPage(
            [
                'name' => strtolower($pageName),
                'type' => strtolower($pageType),
                'revision' => $revisionId,
            ]
        );

        $requestPage = $this->getPage(
            $site,
            $pageName,
            $pageType
        );

        $page = $this->preparePage(
            $site,
            $requestPage,
            $revisionId
        );

        if (empty($page)) {
            $pageData->setHttpStatus(
                $this->pageStatus->getNotFoundStatus()
            );

            return $pageData;
        }

        $pageData->setPage($page);

        $allowed = $this->cmsPermissionChecks->isPageAllowedForReading($page);

        if (!$allowed) {
            $pageData->setHttpStatus(
                $this->pageStatus->getNotAuthorizedStatus()
            );

            return $pageData;
        }

        // @todo FUTURE Insert Block data (plugin data)
        // $pageData->setBlocks([]);

        $pageData->setHttpStatus(
            $this->getStatus(
                $pageData->getRequestedPageName(),
                $page->getName()
            )
        );

        return $pageData;
    }
1280390
public function svnUsers($site)
    {
        $variables = array('site' => $site);
        $request = $this->get(array('{+base_path}/sites/{site}/svnusers.json', $variables));
        return new Response\SvnUsers($request);
    }
784108
public function actionGetSectionUrls(string $section, array $criteria = [], $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getSectionUrls($section, $criteria, $siteId));
    }
847149
public function validateResponse($url, $response)
	{
		if (strpos($url, 'verify_credentials') === false && $response->code != 200)
		{
			$error = json_decode($response->body);

			if (property_exists($error, 'error'))
			{
				throw new \DomainException($error->error);
			}

			$error = $error->errors;

			throw new \DomainException($error[0]->message, $error[0]->code);
		}
	}
50626
protected function prepareDefaultValues(
        Site $site,
        array $defaultSiteSettings,
        string $createdByUserId,
        string $createdReason
    ) {
        $defaults = $this->getDefaultSiteValues(
            $defaultSiteSettings,
            $createdByUserId,
            $createdReason
        );

        foreach ($defaults as $key => $value) {
            $getMethod = 'get' . ucfirst($key);
            $setMethod = 'set' . ucfirst($key);

            $currentValue = $site->$getMethod();

            if (empty($currentValue)) {
                $site->$setMethod($value);
            }
        }

        return $site;
    }
661576
protected function getRemoteResponse($url, array $headers = [])
    {
        $fixedHeaders = ['connection' => 'close'];
        foreach($headers as $key => $header) {
            if (is_int($key)) {
                list($key, $header) = explode(':', $header);
            }
            $key = strtolower($key);
            if (in_array($key, ['cache-control', 'accept', 'user-agent', 'accept-encoding', 'accept-language'])) {
                if (is_array($header)) {
                    $fixedHeaders[$key] = implode('; ', $header);
                }
            }
        }

        $browser = new Browser();
        /** @var \Buzz\Message\Response $res */
        $res = $browser->get($url, $fixedHeaders);
        if ($res->isSuccessful()) {
            $response = new Response($res->getContent(), $res->getStatusCode());
            $headers = [];
            foreach($res->getHeaders() as $header) {
                if (0 < strpos($header, ':')) {
                    list($key, $value) = explode(':', $header);
                    $headers[trim($key)] = trim($value);
                }
            }
            $response->headers->add($headers);
            return $response;
        }

        return null;
    }
1062102
public function getRedirect($url, $siteId)
    {
        if (empty($url)) {
            throw new InvalidArgumentException('No URL found to search by');
        }

        try {
            $result = $this->getQuery($siteId, $url)->getResult();
        } catch (NoResultException $e) {
            return null;
        }

        return array_pop($result);
    }
877000
private function buildResults(Response $response): array
    {
        $data = $response->getData();
        $results = [];

        if (!isset($data['hits']['hits'])) {
            return $results;
        }

        foreach ($data['hits']['hits'] as $hit) {
            $results[] = new Result($hit);
        }

        return $results;
    }
275980
private function getMetaRedirectUriFromResponse(
        ResponseInterface $response,
        UriInterface $lastRequestUri
    ): ?UriInterface {
        /* @var WebPage $webPage */
        try {
            $webPage = Webpage::createFromResponse($lastRequestUri, $response);
        } catch (\Exception $exception) {
            return null;
        }

        $redirectUrl = null;
        $selector = 'meta[http-equiv=refresh]';

        /** @noinspection PhpUnhandledExceptionInspection */
        $inspector = new WebPageInspector($webPage);

        /* @var \DOMElement[] $metaRefreshElements */
        $metaRefreshElements = $inspector->querySelectorAll($selector);

        foreach ($metaRefreshElements as $metaRefreshElement) {
            if ($metaRefreshElement->hasAttribute('content')) {
                $contentAttribute = $metaRefreshElement->getAttribute('content');
                $urlMarkerPosition = stripos($contentAttribute, 'url=');

                if ($urlMarkerPosition !== false) {
                    $redirectUrl = substr($contentAttribute, $urlMarkerPosition + strlen('url='));
                }
            }
        }

        if (empty($redirectUrl)) {
            return null;
        }

        return AbsoluteUrlDeriver::derive($lastRequestUri, new Uri($redirectUrl));
    }