|
1 | 1 | <?php |
| 2 | +include_once 'config.php'; |
2 | 3 | include_once 'simple_html_dom.php'; |
3 | 4 |
|
4 | | -$curl = curl_init('http://forumodua.com/'); |
| 5 | +if(!AUTH_URL){ |
| 6 | + $curl = curl_init('http://forumodua.com/'); |
5 | 7 |
|
6 | | -curl_setopt($curl, CURLOPT_FRESH_CONNECT, true); |
7 | | -curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
8 | | -curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'); |
9 | | -curl_setopt($curl, CURLOPT_HTTPHEADER, [ |
10 | | - "Content-Type: text/xml; charset=utf-8", |
11 | | - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", |
12 | | - "Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,uk;q=0.6" |
13 | | -]); |
| 8 | + curl_setopt($curl, CURLOPT_FRESH_CONNECT, true); |
| 9 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
| 10 | + curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'); |
14 | 11 |
|
15 | | -$result = curl_exec($curl); |
| 12 | + $result = curl_exec($curl); |
16 | 13 |
|
17 | | -curl_close($curl); |
| 14 | + curl_close($curl); |
18 | 15 |
|
19 | | -$html = str_get_html($result); |
| 16 | + $html = str_get_html($result); |
20 | 17 |
|
21 | | -/** @var simple_html_dom_node $form */ |
22 | | -$form = $html->find('#navbar_loginform', 0); |
23 | | -$action = $form->attr['action']; |
| 18 | + /** @var simple_html_dom_node $form */ |
| 19 | + $form = $html->find('#navbar_loginform', 0); |
| 20 | + $authAction = 'http://forumodua.com/'.$form->attr['action']; |
| 21 | +} else{ |
| 22 | + $authAction = AUTH_URL; |
| 23 | +} |
24 | 24 |
|
25 | | -$curl = curl_init('http://forumodua.com/'.$action); |
| 25 | +$curl = curl_init($authAction); |
| 26 | +curl_setopt($curl, CURLOPT_FRESH_CONNECT, true); |
26 | 27 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
27 | 28 | curl_setopt($curl, CURLOPT_COOKIESESSION, false); |
28 | 29 | curl_setopt($curl, CURLOPT_POST, true); |
29 | 30 | curl_setopt($curl, CURLOPT_HEADER, true); |
30 | 31 | curl_setopt($curl, CURLOPT_POSTFIELDS, [ |
31 | | - 'vb_login_username' => 'K@R@NTiN', |
32 | | - 'vb_login_md5password' => md5('100891'), |
33 | | - 'vb_login_md5password_utf' => md5('100891'), |
| 32 | + 'vb_login_username' => USERNAME, |
| 33 | + 'vb_login_md5password' => md5(PASSWORD), |
| 34 | + 'vb_login_md5password_utf' => md5(PASSWORD), |
34 | 35 | 'securitytoken' => 'guest', |
35 | 36 | 'cookieuser' => 1, |
36 | 37 | 'do' => 'login', |
37 | 38 | 'vb_login_password' => '' |
38 | 39 | ]); |
39 | 40 | curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'); |
40 | | -curl_setopt($curl, CURLOPT_HTTPHEADER, [ |
41 | | - "Content-Type: text/xml; charset=utf-8", |
42 | | - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", |
43 | | - "Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,uk;q=0.6" |
44 | | -]); |
45 | 41 |
|
46 | 42 | $result = curl_exec($curl); |
47 | 43 |
|
|
53 | 49 | $cookies .= $cookies ? '; '.$item : $item; |
54 | 50 | } |
55 | 51 |
|
56 | | -curl_setopt($curl, CURLOPT_URL, 'http://forumodua.com/showthread.php?t=851487'); |
| 52 | +if(!THEME_URL){ |
| 53 | + throw new Error('Theme URL is empty'); |
| 54 | +} |
| 55 | + |
| 56 | +curl_setopt($curl, CURLOPT_URL, THEME_URL); |
57 | 57 | curl_setopt($curl, CURLOPT_HTTPGET, true); |
58 | 58 | curl_setopt($curl, CURLOPT_COOKIESESSION, false); |
59 | 59 | curl_setopt($curl, CURLOPT_COOKIE, $cookies); |
|
82 | 82 | } |
83 | 83 |
|
84 | 84 | $postDate = $message->find('.postdate', 0); |
85 | | - $date = $postDate->find('.date', 0)->text(); |
86 | | - $clearDate = preg_replace('/[ \.:]+/', '-', trim($date)); |
| 85 | + $date = preg_replace('/[ ]+/', ' ', trim($postDate->find('.date', 0)->text())); |
| 86 | + $clearDate = preg_replace('/[ \.:]+/', '-', trim($date)); |
87 | 87 |
|
88 | 88 | $fileName = $theme.'-'.$clearDate.'.txt'; |
89 | 89 |
|
90 | 90 | $messageTitle = $message->find('h2.title', 0) ? $message->find('h2.title', 0)->text() : ''; |
91 | 91 | $messageAuthor = $message->find('.userinfo', 0)->find('.username', 0)->text(); |
92 | 92 | $messageText = $message->find('.postbody', 0)->find('blockquote.postcontent', 0)->text(); |
93 | 93 |
|
94 | | - $fileContent = $messageTitle.PHP_EOL.$messageAuthor.PHP_EOL.$messageText; |
| 94 | + $fileContent = trim($messageTitle).PHP_EOL.$messageAuthor.PHP_EOL.$date.PHP_EOL.trim($messageText); |
95 | 95 |
|
96 | 96 | file_put_contents($folder.DIRECTORY_SEPARATOR.$fileName, $fileContent); |
97 | 97 | } |
|
0 commit comments