forked from Gyvastis/article-rewriter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
40 lines (31 loc) · 1.35 KB
/
functions.php
File metadata and controls
40 lines (31 loc) · 1.35 KB
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
<?php
function spin_article($text_to_spin, $include_capitalized = false){
$client = new \Goutte\Client();
$spinner_url = 'http://paraphrasing-tool.com/';
$crawler = $client->request('GET', $spinner_url);
$math_captcha_equation = $crawler->filter('#math_captcha_equation')->first()->attr('value');
$math_captcha_equation = str_replace([
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'
], [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
], $math_captcha_equation);
$math_captcha_equation = explode(' ', $math_captcha_equation);
$math_captcha_result = null;
switch($math_captcha_equation[1]){
case '+':
$math_captcha_result = $math_captcha_equation[0] + $math_captcha_equation[2];
break;
case '-':
$math_captcha_result = $math_captcha_equation[0] - $math_captcha_equation[2];
break;
}
if(is_null($math_captcha_result)){
return false;
}
$crawler = $client->submit($crawler->selectButton('Go!')->form(), [
'math_captcha_answer' => $math_captcha_result,
'formNameLabelTextBefore' => $text_to_spin,
'formNameLabelSpinCapWords' => $include_capitalized
]);
return $crawler->filter('#formNameLabelTextAfter')->first()->text();
}