View file sys/widgets/tsn/index.php

File size: 2.84Kb
<?php 
	defined('DCMS') or die; 
	$site = 'http://'.(($user -> id?$user -> language:$dcms -> language) == 'ukrainian'?'':'ru.').'tsn.ua/';
	$url = $site.'novini-dnya/'.date('d-m-Y').'/';
	$arr_p = explode("\r\n", file_get_contents(H.'/tsn/inc/proxy.dat'));
	$arr_b = explode("\r\n", file_get_contents(H.'/tsn/inc/ua.dat'));
	$c['p'] = $arr_p[array_rand($arr_p, 1)];
	$c['b'] = $arr_b[array_rand($arr_b, 1)];
	unset($arr_p, $arr_b); 
	$list = new listing;
	$elem = $list -> post(); 
	$elem -> icon('news'); 
	$elem -> title = __('Сегодня'); 
	$elem -> url = '/tsn/';
	$elem -> hightlight = true;
	if($str = get_curlopt($url, $c['b'], $c['p'], $site)) {
		$str = preg_replace("/^.*?<div\s+class=[\"']?(content_photo|content|central_news_list|results|search\s+search_word)[\"']?.*?>|<div\s+class=[\"']?sep-0[\"']?>.*$/si", '', $str);
		if(preg_match("/<table\s+class=[\"']?calendar[\"'].*?\/table>/si", $str)) { 
			$str = preg_replace("/<table\s+class=[\"']?calendar[\"'].*?\/table>/si", '', $str); 
		}
		if(preg_match("/<ul\s?class=[\"']?list(_type_1)?[\"']?.*?\/ul>/si", $str)) { 
			preg_match_all("/<li.*?\/li>/si", preg_replace("/^.*?<ul\s+class=[\"']?list_type_1[\"']?>|<\/ul/si", '', $str), $_arr); 
			$_count = count($_arr[0]); 
			if($_count > 0) { 
				if($_count > $dcms -> widget_items_count) { 
					$_arr[0] = array_slice($_arr[0], 0, $dcms -> widget_items_count); 
				}
				print "<style>table tr td.image:nth-child(1) img:nth-child(1) {max-width: 50px!Important;max-height: 50px!Important;min-width: 50px!Important;min-height: 50px!Important;}</style>\r\n";
				foreach($_arr[0] as $post) { 
					$elem = $list -> post();
					if(preg_match("/<a.*?class=[\"']image[\"'].*?\/a>/si", $post)) { 
					/* Скрин */
						$elem -> image = preg_replace("/^.*?<a.*?class=[\"']image[\"'].*?<img\s+src=[\"']|[\"'].*$/si", '', $post);
					}
					if(preg_match("/<h2\s+class=[\"'](title|photo_title)[\"'].*?\/h2>/si", $post)) { 
					/* Заголовок и ссылка поста */
						$elem -> title = preg_replace("/^.*?<h2\s+class=[\"'](title|photo_title)[\"'].*?<a.*?>|<\/a.*$/si", '', $post);
						$elem -> url = '/tsn/?act=read&amp;cat='.str_replace('/', '---', preg_replace("/^.*?<h2\s+class=[\"'](title|photo_title)[\"'].*?<a\s+href=[\"'](http:\/\/(\w+\.)?\w+\.\w+)?\/?|(\.html|[\"']).*$/si", '', $post));
					}
					if(preg_match("/<span\s+class=[\"']?date[\"'].*?\/span>/si", $post)) { 
					/* Дата публикации */
						$elem -> time = preg_replace("/^.*?<span\s+class=[\"']date[\"']>|<\/span.*$/si", '', $post);
					}
					if(preg_match("/<span\s+class=[\"']descr[\"'].*?\/span>/si", $post)) { 
					/* Превью */
						$elem -> post = preg_replace("/^.*?<span\s+class=[\"']descr[\"']>|<\/span.*$/si", '', $post);
					}
					$elem -> hightlight = true;
				}
			}
		}
	}
	$list -> display();
?>