- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
<?php
define('STOCK_URL', 'http://govnokod.ru/comments');
define('REFERER_URL', 'http://govnokod.ru/');
define('AUTH_COOKIES', 'a:2:{s:9:"PHPSESSID";s:26:"k719c8rqcm85dptista7b7rck7";s:4:"auth";s:32:"0ce5a7d54092aa07e37b88ffbe098135";}');
define('MODERATED_TEXT', '[color=red][i]Слава «Беркуту»![/i][/color]');
define('DEFAULT_UA', 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.16');
define('POST_HEADERS', "X-Requested-With: XMLHttpRequest\r\nContent-Type: application/x-www-form-urlencoded\r\n");
define('PONY1', "//ol[@class='posts hatom']/li/h2/a");
define('PONY2', "//form/div/input[@name='_csrf_token']");
define('PONY3', "//li[@class='hcomment']/div/a[@class='edit-comment-link']");
function myCookies() {
$map_cookies = function($k, $v) {return $k . '='. $v;};
return implode('; ', array_map($map_cookies, array_keys(unserialize(AUTH_COOKIES)), unserialize(AUTH_COOKIES)));
}
function huyarim($url, $referer, $mask, $attr) {
$context_options = stream_context_create(array('http' => array(
'method' => 'GET',
'user_agent' => DEFAULT_UA,
'header' => 'Referer: '. $referer . "\r\n" . 'Cookie: ' . myCookies()
)));
$links = array();
$file = @file_get_contents($url, false, $context_options);
if ($file) {
$old_libxml_error = libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTML($file);
libxml_use_internal_errors($old_libxml_error);
$domxpath = new DOMXPath($dom);
$filtered = $domxpath->query($mask);
foreach ($filtered as $item) {
$links[] = $item->getAttribute($attr);
}
}
return $links;
}
function getList() {return huyarim(STOCK_URL, REFERER_URL, PONY1, 'href');}
function getCsrf($url) {$tokens = huyarim($url, STOCK_URL, PONY2, 'value'); return $tokens[0];}
function getComments($url) {return huyarim($url, STOCK_URL, PONY3, 'href');}
function doPost($url, $referer, $token) {
$postdata = http_build_query(array(
'_csrf_token' => $token,
'text' => MODERATED_TEXT,
'commentSubmit' => 'Отправить комментарий [Ctrl+Enter]',
'ajax' => 'true'
));
$context_options = stream_context_create(array('http' => array(
'protocol_version' => 1.1,
'method' => 'POST',
'user_agent' => DEFAULT_UA,
'header' => POST_HEADERS . 'Referer: '. $referer . "\r\n" . 'Cookie: ' . myCookies(),
'content' => $postdata
)));
return file_get_contents($url, false, $context_options);
}
$links = getList();
foreach($links as $link) {
$token = getCsrf($link);
$comments = getComments($link);
foreach($comments as $comment) {
if (false !== doPost($comment, $link, $token)) {
echo $comment . ' OK' . PHP_EOL;
}
}
}
CURL и PECL_HTTP не нужны. Да, и ООП тоже не нужно.