<?PHP 

    # Пишу скрипты, модули с 0 
    # PHP <> 7.4, MySQL,MySQL(i),PDO
    # author penny wise
    # telegram @the_penny_wise

    # загрузка функции

    function curl($url,$post = null) {   # подключение по curl к сайту

	$curl = curl_init();  
	$ua = 'Nokia 6230';	
	$headers = array(
	'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
	'Accept-Language:ru,en-US;q=0.8,en;q=0.6,uk;q=0.4',
	'Referer:' . $url,$ua);
	curl_setopt($curl, CURLOPT_URL, $url);  
	curl_setopt($curl, CURLOPT_USERAGENT, $ua);  
	curl_setopt($curl, CURLOPT_REFERER, $url);  
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);  
	curl_setopt($curl, CURLOPT_TIMEOUT, 60); 
	curl_setopt($curl, CURLOPT_COOKIEJAR, ROOT.'/_sys/_cookies/afilm.dat');
	curl_setopt($curl, CURLOPT_COOKIEFILE, ROOT.'/_sys/_cookies/afilm.dat');
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_HEADER, 1);
	if($post != null) :
	curl_setopt($curl, CURLOPT_POST, 1);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
	endif;
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
	$cnt = curl_exec($curl);  
	curl_close($curl); 
	return $cnt;  

	}   
	
	function get_index ($get,$search = null) { # индек страница

	preg_match('#<title>(.*)</title>#sU', $get, $title);
	preg_match('#<meta name="description" content="(.*)"#sU', $get, $description);
	preg_match_all('#<div class="my_razdel film">(.*)</a>#sU', $get, $data);	
	
	$title[1] = str_replace(['Анвап','anwap','анвап','Anwap.TV'],DOMAIN,$title[1]);
	$title[1] = stripslashes(trim($title[1]));	

	$description[1] = str_replace(['Анвап','anwap','анвап','Anwap.TV'],DOMAIN,$description[1]);
	$description[1] = stripslashes(trim($description[1]));	
	
	$meta = [
	'title' => $title[1], # титле мета
	'description' => $description[1] # описание мета
	];	

	$cache ='[{"title":"'.$meta['title'].'","description":"'.$meta['description'].'"}, {';

	for($i = 0; $i<count($data[1]); $i++):	
	
	preg_match('#<a href="/films/(.*)">#sU', $data[1][$i], $afilm);
	preg_match('#<span class="newhit">(.*)</span>#sU', $data[1][$i], $new);
	preg_match('#<img src="(.*)"(.*)title="(.*)"#sU', $data[1][$i], $img);
	preg_match('#<div class="namefilm">(.*)</div>#sU', $data[1][$i], $name);
	preg_match('#<span class="in green">(.*)</span>#sU', $data[1][$i], $green);
	preg_match('#<span class="in sound">(.*)</span>#sU', $data[1][$i], $sound);
	preg_match('#<span class="in year">(.*)</span>#sU', $data[1][$i], $year);
	preg_match('#<span class="discripfilm">(.*)</span>#sU', $data[1][$i], $discripfilm);	


	# удаляем пробелы
	$trim_msg = ['\'','	',];
	$discripfilm[1] = str_replace($trim_msg,'',$discripfilm[1]);
	$discripfilm[1] = stripslashes(trim($discripfilm[1]));
	$discripfilm[1] = preg_replace('/[^\p{L}0-9]/iu',' ',strip_tags($discripfilm[1])); 

	$date = [
	'url' => $afilm[1] , # url
	'new' => (isset($new[1])  ? $new[1] : null), # новый
	'src' => 'https://'.DOMAIN.'/films/prew/'.base64_encode(($search != null ? URL:'').$img[1]), # постер
	'sti' => $img[3], # титле постера
	'name' => $name[1],	# имя фильма
	'green' => $green[1],	# качество фильма
	'sound' => $sound[1],	# звук фильма	
	'year'  => $year[1],	# год фильма	
	'discripfilm'  => $discripfilm[1]	# описание фильма	
	];	

	$cache.='"url":"'.$date['url'].'","new":"'.$date['new'].'","src":"'.$date['src'].'",
			"sti":"'.$date['sti'].'","name":"'.$date['name'].'","green":"'.$date['green'].'",
			"sound":"'.$date['sound'].'","year":"'.$date['year'].'","discripfilm":"'.$date['discripfilm'].'"
			}, {';

	preg_match_all('#<span class="in genre">(.*)</span>#sU', $data[1][$i], $genre);

	for($s = 0; $s<count($genre[1]); $s++):

	$arr = ['genre_url' => $afilm[1], 'genre'=> $genre[1][$s]]; # жанры	

	$cache.='"genre_url":"'.$arr['genre_url'].'","genre":"'.$arr['genre'].'"}, {';

	endfor;		

	endfor;		

	$cache.= '}]';

	return @json_decode($cache);

	}

	function get_genre ($get) { # жанры

	preg_match('#<title>(.*)</title>#sU', $get, $title);
	preg_match('#<meta name="description" content="(.*)"#sU', $get, $description);

	$title[1] = str_replace(['Анвап','anwap','анвап','Anwap.TV'],DOMAIN,$title[1]);
	$title[1] = stripslashes(trim($title[1]));	

	$description[1] = str_replace(['Анвап','anwap','анвап','Anwap.TV'],DOMAIN,$description[1]);
	$description[1] = stripslashes(trim($description[1]));	
	
	$meta = [
	'title' => $title[1], # титле мета
	'description' => $description[1] # описание мета
	];	

	$cache ='[{"title":"'.$meta['title'].'","description":"'.$meta['description'].'"}, {';

	preg_match('#<ul class="tl">(.*)</ul>#sU', $get, $dt);	

	preg_match_all('#<a href="/films/(.*)">(.*)</a>#sU', $dt[1], $data);	

	for($i = 0; $i<count($data[1]); $i++):	
	
	preg_match('#(.*)<span#sU', $data[2][$i], $name);
	preg_match('#<span class="black">(.*)</span>#sU', $data[2][$i], $black);
	preg_match('#<span class="cb">(.*)</span>#sU', $data[2][$i], $cb);
	preg_match('#<span class="c1">(.*)</span>#sU', $data[2][$i], $c1);

	$date = [
	'url'  =>  $data[1][$i], # url
	'name' =>  $name[1], # название
	'black' =>  $black[1], # cnt
	'cb' => (isset($cb[1])  ? $cb[1] : null), # cnt
	'c1' => (isset($c1[1])  ? $c1[1] : null) # cnt
	];

	$cache.='"url":"'.$date['url'].'","name":"'.$date['name'].'","black":"'.$date['black'].'","cb":"'.$date['cb'].'","c1":"'.$date['c1'].'"}, {';

	endfor;

	$cache.= '}]';

	return @json_decode($cache);

	}
	

	function page_index ($get,$search = null,$genre = null) { # page

	preg_match('#<div class="gffghgjh">(.*)</div>#sU', $get, $pages);	

	$pages[1] = str_replace(
	['/films','/top&','/new-'],
	['https://'.DOMAIN.'/films','/top/p-','/new/p-'],$pages[1]);

	if ($genre != null ):

	$pages[1] = str_replace('/films/'.$genre.'-','/films/genre/'.$genre.'/p-',$pages[1]);	

	endif;

	if ($search != null):

	$pages[1] = str_replace(['/search/'.$search['vid'].'/','?slv='.$search['slv'].'','toch='.$search['toch'].'','page=','amp;','&'],['/search/','','','p-','',''],$pages[1]);

	endif;	

	$pages[1] = stripslashes(trim($pages[1]));

	echo '<div class="gffghgjh">'.$pages[1].'</div>';
	
	}	