This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
85 lines (77 loc) · 2.07 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types = 1);
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
/**
* Based on javascript findAnswer() function into /adpagespeed.js
*
* @param string $token
* @return string
*/
function findAnswer(string $token): string {
$replacements = [
'a' => 'z',
'b' => 'y',
'c' => 'x',
'd' => 'w',
'e' => 'v',
'f' => 'u',
'g' => 't',
'h' => 's',
'i' => 'r',
'j' => 'q',
'k' => 'p',
'l' => 'o',
'm' => 'n',
'n' => 'm',
'o' => 'l',
'p' => 'k',
'q' => 'j',
'r' => 'i',
's' => 'h',
't' => 'g',
'u' => 'f',
'v' => 'e',
'w' => 'd',
'x' => 'c',
'y' => 'b',
'z' => 'a',
];
for ($t = 0; $t < strlen($token); $t++) {
$token[$t] = array_key_exists($token[$t], $replacements) ? $replacements[$token[$t]] : $token[$t];
}
return $token;
}
/**
* @param ResponseInterface $response
* @return string
* @throws ClientExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
*/
function getCookie(ResponseInterface $response): string {
return $response->getHeaders()['set-cookie'][0];
}
/**
* @param ResponseInterface $response
* @return string
* @throws ClientExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
*/
function getTokenForm(ResponseInterface $response): string {
$crawler = new Crawler($response->getContent());
return $crawler
->filter("#token")
->getNode(0)
->attributes
->getNamedItem('value')
->nodeValue
;
}