<?php

//By FlySelf

define('_IN_JOHNCMS', 1);

$headmod = 'horo';
$textl = 'Гороскоп';
require_once("../incfiles/core.php");
require_once('../incfiles/head.php');
$time_file = @ filemtime('cache/clean.dat');
if (date('d.m.y', $realtime) != date('d.m.y', $time_file)) {
	$dir_clean = opendir('cache');
	while ($file = readdir($dir_clean)) {
		if ($file != '.' && $file != '..'&& $file != '.htaccess') {
			@ unlink ('cache/' . $file);
		}
	}
	closedir($dir_clean);
	@ file_put_contents('cache/clean.dat', 1);
}

function contents($url) {
	global $home;
	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_TIMEOUT, 10);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: text/html, application/xml, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;', 'Accept-Language: ru, en, *;', 'Accept-Charset: iso-8859-1, utf-8, utf-16, *;', 'Accept-Encoding: identity;', 'Connection: close'));
	curl_setopt($curl, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.6.22 Version/10.50');
	curl_setopt($curl, CURLOPT_REFERER, $home);
	$contents = curl_exec($curl);
	curl_close();
	return $contents;
}

$file_cache = 'cache/' . md5($_SERVER['REQUEST_URI']) . '.dat';

if (file_exists($file_cache)) {
	echo file_get_contents($file_cache);
	require_once ("../incfiles/end.php");
	exit;
}

$array = array('forecast', 'weekend', 'citychange', 'search', 'near', 'citylist');
if ($act && file_exists('prediction.php')) {
    require ('prediction.php');
} else {
	$array = array('yesterday', 'tomorrow', 'week', 'month', 'year');
    $contents = contents('http://wap.horo.mail.ru/index.html' . (in_array($mod, $array)? '?time=' . $mod : ''));
    $contents = preg_replace('/<\?xml(.*?)<div class=\"inner\">/si', '', $contents);
    $contents = preg_replace('/<h1>(.*?)<\/h1>/si', '<div class="phdr"><b>\1</b></div><div class="bmenu">', $contents);
    $contents = preg_replace('/<div id=\"footer\"(.*?)<\/html>/si', '</div><div class="phdr"><br /></div>', $contents);
    $contents = preg_replace('/<div class=\"inner\">(.*?)<\/div>/si', '\1', $contents);
    $contents = strtr($contents, array('=17' => '="17"', '&time' => '&amp;time', '<p>&#032;</p>' => '', '<p>&#032;</p><br/>' => '', '<br/>' => '</div><div class="list1">', '<p>' => '', '</p>' => '<br />', '/img/zodiac' => 'images', '/index' => 'index', '/prediction' => 'prediction'));
    $contents = preg_replace('/<div class=\"list1\">(.*?)<\/div>/si', '<div class="list1">\1</div><div class="list2">', $contents);
    $contents = preg_replace('/\.html\?sign=([0-9]+)&amp;time=(1|yesterday|tomorrow|week|month|year|today)/si', '_\1_\2.html', $contents);
    $contents = preg_replace('/\.html\?time=(1|yesterday|tomorrow|week|month|year|today)/si', '_\1.html', $contents);
}
if($contents) {
	echo $contents;
	@ file_put_contents($file_cache, $contents);
}
else
	echo '<div class="rmenu"><p>Сервис временно не доступен!</p></div>';

require_once('../incfiles/end.php');

?>