1+ <?php
2+ include_once 'simple_html_dom.php ' ;
3+
4+ $ curl = curl_init ('http://forumodua.com/showthread.php?t=851487 ' );
5+
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+ ]);
14+
15+ $ result = curl_exec ($ curl );
16+
17+ curl_close ($ curl );
18+
19+ $ html = str_get_html ($ result );
20+
21+ $ messages = $ html ->find ('.postbitlegacy ' );
22+ $ theme = $ html ->find ('title ' , 0 )->text ();
23+ $ folder = __DIR__ .DIRECTORY_SEPARATOR .'posts ' ;
24+
25+ if ($ messages ){
26+ /** @var simple_html_dom_node $message */
27+ foreach ($ messages as $ message ){
28+ if (!isset ($ message ->attr ['id ' ])){
29+ continue ;
30+ }
31+
32+ $ isMessage = preg_match ('/^post/ ' , $ message ->attr ['id ' ]);
33+
34+ if ($ isMessage === false ){
35+ continue ;
36+ }
37+
38+ $ postDate = $ message ->find ('.postdate ' , 0 );
39+ $ date = $ postDate ->find ('.date ' , 0 )->text ();
40+ $ clearDate = preg_replace ('/[ \.:]+/ ' , '- ' , trim ($ date ));
41+
42+ $ fileName = $ theme .'- ' .$ clearDate .'.txt ' ;
43+
44+ $ messageTitle = $ message ->find ('h2.title ' , 0 ) ? $ message ->find ('h2.title ' , 0 )->text () : '' ;
45+ $ messageAuthor = $ message ->find ('.userinfo ' , 0 )->find ('.username ' , 0 )->text ();
46+ $ messageText = $ message ->find ('.postbody ' , 0 )->find ('blockquote.postcontent ' , 0 )->text ();
47+
48+ $ fileContent = $ messageTitle .PHP_EOL .$ messageAuthor .PHP_EOL .$ messageText ;
49+
50+ file_put_contents ($ folder .DIRECTORY_SEPARATOR .$ fileName , $ fileContent );
51+ }
52+ }
0 commit comments