<?php
define('DEBUG', false);
$debug = array();
if (DEBUG) {
@error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
@ini_set('error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE);
@ini_set('display_errors', true);
@ini_set('html_errors', true);
} else {
@error_reporting(E_ERROR);
@ini_set('error_reporting', E_ERROR);
@ini_set('display_errors', true);
@ini_set('html_errors', false);
}
@ini_set('max_execution_time', '1800');
@set_time_limit(1800);
if (get_magic_quotes_runtime()) {
set_magic_quotes_runtime(false);
}
$d= $_POST['url'];
if($d){
$h = '1';
}
$tio = isset($h) ? intval($h) : false;
$tio = floor(lcg_value() * (999 - 2) + 2);
file_get_contents('C:\/OSPanel\/domains\/kinopoisk\/config.php');
//Функция вывода на экран
function printData($json, $error = false)
{
global $debug, $parser;
@header('Content-Type: text/html; charset=UTF-8');
if (!$error) {
if (is_string($json)) {
$json = array('text' => $json);
}
if (DEBUG) {
$json['debug'] = $debug;
if (isset($parser->debug_list)) {
$json['debug_parser'] = $parser->debug_list;
}
}
$json = json_encode($json);
if (DEBUG and function_exists('json_last_error') and json_last_error()) {
$json = array(
'debug_json' => json_last_error()
);
$json = json_encode($json);
}
//echo $json;
} else {
$json = array('text' => '<span style="color: red;">'.$json.'</span>');
//echo json_encode($json);
set_file_info('delete');
exit;
}
}
/**
* Введите информацию о статусе
* @Строка param @info
* @обратная смесь
*/
//установить информацию о файле
function set_file_info($info)
{
global $tio;
if (!$tio) {
return false;
}
if ($info == 'delete') {
@unlink('./cache/pkinopoisk_tio_'.$tio.'.tmp');
} elseif ($info) {
if (file_exists('./cache/pkinopoisk_tio_'.$tio.'.tmp')) {
$info = '<br />'.$info;
}
$fh = fopen('./cache/pkinopoisk_tio_'.$tio.'.tmp', 'a+');
fwrite($fh, $info);
fclose($fh);
}
}
/**
* Преобразование кодировки в utf-8
* @Параметр строки $ data
* @Параметр строки $from
* @Параметр строки $to
* @строка возврата
*/
function convert_charset_pkp($data, $from = 'cp1251', $to = 'utf-8')
{
if ($from == $to) {
return $data;
} elseif (function_exists('mb_convert_encoding')) {
$data = mb_convert_encoding($data, $to, $from);
} elseif (function_exists('iconv')) {
$data = iconv($from, $to.'//IGNORE', $data);
}
return $data;
}
/**
* Заменяем ASCII код в соответствующий html спец. код
* @param string $text
* @return string
*/
function convert_charset_ascii_to_code($text)
{
//http://easywebscripts.net/html/ascii.php
$sc = array('"', '&', '~', '‚', '„', '†', '‡', '‰', '‹', '‘', '’', '“', '”', '–', '—', '˜', '™', '›', 'Ÿ', ' ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', '…');
$rp = array('"', '&', '˜', '‚', '&dbquo;', '†', '‡', '‰', '‹', '‘', '’', '“', '”', '–', '—', '&tilde', '™', '›', 'Ÿ', ' ', '&ixcl;', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', '³', '&acuate;', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', '&Icirс;', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', '&icirс;', 'ð', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', '...',);
$text = str_replace($sc, $rp, $text);
return $text;
}
if (isset($_POST['id']) && $_POST['id'] == 'tio' && $tio) {
if (file_exists('/.cache/pkinopoisk_tio_'.$tio.'.tmp')) {
$time_file = @filemtime('./cache/pkinopoisk_tio_'.$tio.'.tmp');
$time_file = $time_file ? ' ('.(time() - $time_file).' сек.)' : '';
printData('<span style="color: green;">'.file_get_contents('./cache/pkinopoisk_tio_'.$tio.'.tmp').$time_file.'</span>');
} else {
printData('finish');
}
die();
}
//DLE function
@session_start();
$prefix_link_tags = 'tags/';
//Mod main
$_TIME = time() + ($config_mod['date_adjust'] * 60);
@session_write_close();
//$config_mod =
define('FOLDER_PREFIX', date("Y-m"));
$news_id = isset($_POST['news_id']) ? intval($_POST['news_id']) : 0;
$author = "igrovik";
$time_ex = time();
/*if (get_magic_quotes_gpc()) {
$_POST['film_name'] = stripslashes($_POST['film_name']);
}
$title = trim($_POST['url']);
$sact = isset($_POST['sact']) ? trim(strip_tags($_POST['sact'])) : false;
if (empty($title)) {
printData('Для поиска введите название фильма в заголовок статьи!', true);
}
*/
$config_mod['conf']['sleep'] = intval($config_mod['conf']['sleep']);
if ($config_mod['conf']['jpeg_quality'] <= 0) {
$config_mod['conf']['jpeg_quality'] = $config['jpeg_quality'];
}
if (!empty($config_mod['conf']['http_site'])) {
$config['http_home_url'] = $config_mod['conf']['http_site'];
}
/**
* Class Parser
* Класс парсера. Работает через curl, поддерживает post.
*/
class Parser
{
const PROXY_TYPE_HTML = 1;
const PROXY_TYPE_SOCKS5 = 2;
public $debug = false;
public $debug_list = array();
private $_curl_timeout = 120;
private $_user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0';
private $_proxy_type = false;
private $_proxy = '';
private $_cookie_file = '';
private $_dir_cache = false;
public $cached = false;
/**
* Максимальное количество редиректов, актуально если не работает опция CURLOPT_FOLLOWLOCATION
* @var int
*/
private $_redirect_max = 5;
private $_redirect_current = 0;
private $_sleep = 2;
private $_last_active_time = 0;
/**
* Ссылка на обработчик cUrl
* @var bool|resource
*/
private $_ch = false;
public function initClose()
{
curl_close($this->_ch);
$this->_ch = false;
}
/**
* Устанавливает файл cookie, если файла нет создает
* @param $cookie_file
* @param bool $new Если true, старый файл будет очищен
*/
public function setCoolieFile($cookie_file, $new = false)
{
if (!$new and file_exists($cookie_file)) {
$this->_cookie_file = $cookie_file;
} elseif (file_put_contents($cookie_file, ' ', LOCK_EX)) {
chmod($cookie_file, 0666);
$this->_cookie_file = $cookie_file;
} else {
$this->_cookie_file = null;
}
if ($this->_ch) {
curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookie_file);
curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->_cookie_file);
}
}
/**
* Устанавливает время задержки между запросами
* @param int $sleep Время задержки в сек.
*/
public function setSleep($sleep)
{
$sleep = intval($sleep);
$this->_sleep = $sleep > 0 ? $sleep : 0;
}
/**
* Устанавливает user agent для запроса.
* @param string $user_agent
*/
public function setUserAgent($user_agent)
{
$this->_user_agent = $user_agent;
if ($this->_ch) {
curl_setopt($this->_ch, CURLOPT_USERAGENT, $this->_user_agent);
}
}
/**
* Устанавливает путь до кеша для запроса.
* @param string $dir_cache
*/
public function setDirCache($dir_cache)
{
if (is_dir($dir_cache)) {
$this->_dir_cache = $dir_cache;
}
}
/**
* Устанавливает прокси
* @param $proxy
* @param $proxy_type Может принимать self::PROXY_TYPE_HTML или self::PROXY_TYPE_SOCKS5
*/
public function setProxy($proxy, $proxy_type)
{
if (!empty($proxy)) {
if ($proxy_type == self::PROXY_TYPE_HTML) {
$this->_proxy_type = self::PROXY_TYPE_HTML;
$this->_proxy = $proxy;
} elseif ($proxy_type == self::PROXY_TYPE_SOCKS5) {
$this->_proxy_type = self::PROXY_TYPE_SOCKS5;
$this->_proxy = $proxy;
}
}
}
/**
* Инициализирует curl, создает обработчик curl
*/
private function _initCurl()
{
if (!$this->_ch) {
$this->_ch = curl_init();
curl_setopt($this->_ch, CURLOPT_USERAGENT, $this->_user_agent);
@curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->_ch, CURLOPT_TIMEOUT, $this->_curl_timeout);
curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookie_file);
curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->_cookie_file);
if ($this->_proxy_type == self::PROXY_TYPE_HTML) {
curl_setopt($this->_ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
curl_setopt($this->_ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($this->_ch, CURLOPT_PROXY, $this->_proxy);
} elseif ($this->_proxy_type == self::PROXY_TYPE_SOCKS5) {
curl_setopt($this->_ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($this->_ch, CURLOPT_PROXY, $this->_proxy);
}
$curl_version = curl_version();
if (preg_match('#^([0-9]+)\.([0-9]+)#is', $curl_version['version'], $match) and $match[1] >= 7 and $match[2] >= 10) {
if (function_exists('gzdecode')) {
curl_setopt($this->_ch, CURLOPT_ENCODING, 'gzip, deflate');
} else {
curl_setopt($this->_ch, CURLOPT_ENCODING, '');
}
}
curl_setopt($this->_ch, CURLOPT_HTTPHEADER, array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Cache-Control: max-age=0',
'DNT: 0',
'Connection: keep-alive',
'Proxy-Connection:'
));
curl_setopt($this->_ch, CURLOPT_HEADER, 1);
}
}
/**
* Загружает страницу. Публичный
* @param $url
* @param bool $refer
* @param bool $post
* @return bool|mixed|string
*/
public function loadPage($url, $refer = false, $post = false)
{
if (($page = $this->_getCache($url.http_build_query($post))) and !$this->debug) {
return $page;
}
$this->_redirect_current = 0;
$this->_initCurl();
if ($refer) {
curl_setopt($this->_ch, CURLOPT_REFERER, $refer);
} else {
curl_setopt($this->_ch, CURLOPT_REFERER, null);
}
if ($post) {
curl_setopt($this->_ch, CURLOPT_POST, true);
curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $post);
} else {
curl_setopt($this->_ch, CURLOPT_POST, false);
curl_setopt($this->_ch, CURLOPT_HTTPGET, true);
}
$page = $this->_load($url);
$this->_setCache($url.http_build_query($post), $page);
return $page;
}
private function _load($url)
{
if ($this->_redirect_current >= $this->_redirect_max) {
return false;
}
if ($this->_sleep > 0) {
if (($this->_last_active_time + $this->_sleep) > time()) {
sleep($this->_sleep);
}
$this->_last_active_time = time();
}
if ($this->debug) {
curl_setopt($this->_ch, CURLINFO_HEADER_OUT, true);
}
curl_setopt($this->_ch, CURLOPT_URL, $url);
$page = curl_exec($this->_ch);
$curl_info = curl_getinfo($this->_ch);
if ($this->debug) {
$this->debug_list[] = array(
'url' => $url,
'request_header' => $curl_info['request_header'],
'header' => substr($page, 0, $curl_info['header_size']),
'body' => convert_charset_pkp(substr($page, $curl_info['header_size']), $from = 'cp1251', $to = 'utf-8'),
'curl_errno' => curl_errno($this->_ch),
'curl_error' => curl_error($this->_ch)
);
}
if ($curl_info['http_code'] == 301 or $curl_info['http_code'] == 302) {
$header = substr($page, 0, $curl_info['header_size']);
if (preg_match('/Location:(.*?)(\n|$)/is', $header, $matches) and ($url = parse_url(trim($matches[1])))) {
$url['scheme'] = $url['scheme'] ? $url['scheme'] : 'http';
$url['host'] = $url['host'] ? $url['host'] : 'megapesni.me';
$url['path'] = $url['path'] ? $url['path'] : '';
$url['query'] = $url['query'] ? '?'.$url['query'] : '';
$url = $url['scheme'].'://'.$url['host'].$url['path'].$url['query'];
$this->_redirect_current++;
return $this->_load($url);
} else {
return false;
}
}
$page = substr($page, $curl_info['header_size']);
return $page;
}
/**
* Записывает данные в кеш
* @param $url
* @param $page
* @return bool|int
*/
private function _setCache($url, $page)
{
if ($this->cached and $this->_dir_cache) {
return file_put_contents($this->_dir_cache.'/parser_cache_page_'.md5($url).'.tmp', $page, LOCK_EX);
}
return false;
}
/**
* Берет данные из кеша
* @param $url
* @return bool|string
*/
private function _getCache($url)
{
if ($this->cached and $this->_dir_cache) {
$file = $this->_dir_cache.'/parser_cache_page_'.md5($url).'.tmp';
if (file_exists($file)) {
return file_get_contents($file);
}
}
return false;
}
}
$parser = new Parser();
$parser->debug = DEBUG;
$parser->setDirCache('./cache');
$parser->cached = true;
$proxy_type = 0;
if ($config_mod['conf']['proxy_type'] == 1) {
$proxy_type = Parser::PROXY_TYPE_HTML;
} elseif ($config_mod['conf']['proxy_type'] == 2) {
$proxy_type = Parser::PROXY_TYPE_SOCKS5;
}
$parser->setProxy($config_mod['conf']['proxy'], $proxy_type);
if (isset($_SERVER['HTTP_USER_AGENT']) && strlen($_SERVER['HTTP_USER_AGENT']) > 25) {
$parser->setUserAgent($_SERVER['HTTP_USER_AGENT']);
}
define('MOD_COOKIE_FILE', './cache/cookie_www.kinopoisk.ru.tmp');
define( 'FOLDER_PREFIX', date( "Y-m" ) );
/**
* Удаляем файл cookie и создаем пустой новый файл
*/
function clear_cookie_file()
{
@unlink(MOD_COOKIE_FILE);
$fh = fopen(MOD_COOKIE_FILE, 'w');
fwrite($fh, '');
fclose($fh);
chmod(MOD_COOKIE_FILE, 0666);
}
if (!is_file(MOD_COOKIE_FILE) or filemtime(MOD_COOKIE_FILE) < (time() - 43200)) {
clear_cookie_file();
}
$parser->setCoolieFile(MOD_COOKIE_FILE);
set_file_info('delete');
if (!($refer = $author)) {
$refer = 'http://megapesni.me/';
}
$url_link = 'http://megapesni.me/popsa/139692-vremja-i-steklo-ebojj.html';
$pars_oboi = $parser->loadPage($url_link);
echo $pars_oboi;
?>