<?php
/* ====================
Seditio - Website engine
Copyright Neocrome
http://www.neocrome.net
[BEGIN_SED]
File=plugins/pogoda/pogoda.index.php
Version=100
Updated=2006-mar-30
Type=Plugin
Author=Amro
Description=Pogoda
[END_SED]
[BEGIN_SED_EXTPLUGIN]
Code=pogoda
Part=main
File=pogoda.index
Hooks=index.tags
Tags= index.tpl:{POGODA},{POGODA_TOWN}
Order=10
[END_SED_EXTPLUGIN]
==================== */
if (!defined('SED_CODE')) { die('Wrong URL.'); }
$pogodacash = "plugins/pogoda/pogodacashe.txt";
$valutacash = "plugins/pogoda/valutacashe.txt";
$town = $cfg['plugin']['pogoda']['town'];
$timeupdate = $cfg['plugin']['pogoda']['timeupdate'];
$pogstring = $cfg['plugin']['pogoda']['pogstring'];
$timeupdate = $timeupdate*3600;
$towncode = substr($town,0,5); //код города в системе гисметео
$townname = substr($town,5); //название города
function file_get_contentz ($link) {
$url_parts = @parse_url( $link );
$documentpath = $url_parts["path"];
$documentpath .= "?" . $url_parts["query"];
$host = $url_parts["host"];
$port = $url_parts["port"];
$fp = @fsockopen( $host, 80, $errno, $errstr, 5 );
if(!$fp) return false;
fwrite ($fp, "GET ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
while(!feof($fp)) $fcon.=fgets($fp, 1024);
fclose($fp);
$fcon2=explode("\r\n\r\n",$fcon,2);
return $fcon2[1];
}
if (file_exists($pogodacash))
{
$c = file_get_contents($pogodacash);
$arr=explode('#pr#',$c);
if (time()-$arr[0]>$timeupdate)
{
$adr="http://informer.gismeteo.ru/html/informer.php?codepg=UTF-8&index=".$towncode."&par=".$pogstring."&lang=&vieinf=sm";
$n = file_get_contentz($adr);
if ($n)
{
$n = str_replace('document.write("','',$n);
$n = str_replace('");','',$n);
$n = str_replace('\"','"',$n);
$n = preg_replace('/ +/', ' ', $n);
$n = str_replace('</td><tr>','</td></tr><tr>',$n);
$n = preg_replace("'id=(.*?) 'si","",$n);
$n = preg_replace("' class=(.*?)'si","",$n);$n = preg_replace('/""/', '', $n);
$n = str_replace('<td width="20%" align="center">','</td><td width="20%" align="center">',$n);
$n = str_replace('http://informer.gismeteo.ru/html/images/sm/','plugins/pogoda/img/',$n);
$n = preg_replace("'<tr><td colspan=\"3\" align=\"center\">(.*?)<td heigth=\"5\" colspan=\"3\"></td></tr>'si","",$n);
$n = preg_replace("'<tr><td colspan=\"3\" width=\"100%\"><b>(.*?)</b></td></tr>'si","",$n);
$fp=fopen($pogodacash,'w');
fwrite($fp,time().'#pr#'.$n);
fclose($fp);
$arr[1]=$n;
}
else {$arr[1] = "Данные недоступны";}
}
$plugin_pogoda = $arr[1];
}
else
{
$plugin_pogoda = 'Данные недоступны';
}
$t-> assign(array(
"POGODA" => $plugin_pogoda,
"POGODA_TOWN" => $townname
));
?>