예제 #1
0
    function show($data, $tpl)
    {
        global $modx;
        $def_top = <<<HERE
<div class="weather_outer"><div class="w_town">{$data['town']}</div>
<table class="weather_table" cellspacing="0px">
HERE;
        $default_tpl = <<<HERE
\t<tr>
\t\t<td class="w_tod">[+tod+]</td>
\t\t<td class="w_out_ico"><img src="[+ico+]" class="w_ico"></td>
\t\t<td class="w_right">[+temperature_min+]&nbsp;&mdash; [+temperature_max+]&#176;</td>
\t</tr>
HERE;
        $def_bottom = <<<HERE
</table>
\t\t<a href="http://www.gismeteo.ru" class="w_backlink">Предоставлено Gismeteo.Ru</a>
\t</div>
HERE;
        $outs = array($def_top);
        foreach ($data[forecast] as $param) {
            //icon find
            $ico_precipitation = array(4 => 'rain.png', 5 => 'rain.png', 6 => 'snow.png', 7 => 'snow.png', 8 => 'storm.png');
            $ico_cloudiness = array('clear.png', 'few-clouds.png', 'clouds.png', 'clouds.png');
            $ico = $ico_precipitation[$param[phenomena_precipitation]];
            if (!$ico) {
                //if no precipitations - show cloudiness
                $ico = $ico_cloudiness[$param[phenomena_cloudiness]];
            }
            $translate_path = SNIPPET_PATH . 'translate-' . LANG . '.inc.php';
            if (file_exists($translate_path)) {
                require $translate_path;
            }
            foreach ($param as $k => &$v) {
                $v = isset($translate[$k]) ? Gis::recode('utf-8', MODX_CHARSET, $translate[$k][$v]) : $v;
            }
            $param[town] = $data[town];
            preg_match('/(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)/', $param[date], $m);
            $param[fulldate] = $param[date];
            $param[date] = $m[1] . '.' . $m[2];
            $param[yyyy] = $m[3];
            $param[yy] = substr($m[3], 2);
            $param[dd] = $m[1];
            $param[d] = preg_replace('/^0/', '', $m[1]);
            $param[mm] = $m[2];
            $param[m] = preg_replace('/^0/', '', $m[2]);
            $param[smonth] = Gis::recode('utf-8', MODX_CHARSET, $months[$param[m]]);
            $param[ico] = '/assets/snippets/gismeteo/Silk/' . $ico;
            array_push($outs, Gis::parse_tpl($default_tpl, $param));
        }
        array_push($outs, $def_bottom);
        $output = implode("\n\n", $outs);
        $output = Gis::recode('UTF-8', MODX_CHARSET, $output);
        $modx->regClientCSS($modx->config['base_url'] . 'assets/snippets/gismeteo/Silk/theme.css');
        return $output;
    }
    if (!$source) {
        return "Can't get xml from gismeteo.ru";
    }
    //cache
    Gis::rewrite_cache($source, $timemark, $region, $updates);
}
//parsing
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $source, $vals, $index);
xml_parser_free($xml_parser);
$data = array();
$cur_key = 0;
foreach ($vals as $i => $elm) {
    if (!$data[town] && $elm[tag] == 'TOWN' && $elm[attributes][SNAME]) {
        //url-decode
        $data[town] = Gis::recode('Windows-1251', MODX_CHARSET, urldecode($elm[attributes][SNAME]));
    }
    if ($elm[tag] == 'FORECAST' && $elm[type] == 'open') {
        //forecast parsing
        $date = $elm[attributes][DAY] . '.' . $elm[attributes][MONTH] . '.' . $elm[attributes][YEAR];
        $cur_key++;
        $data[forecast][$cur_key][weekday] = $elm[attributes][WEEKDAY];
        $data[forecast][$cur_key][hour] = $elm[attributes][HOUR];
        $data[forecast][$cur_key][tod] = $elm[attributes][TOD];
        $data[forecast][$cur_key][date] = $date;
    }
    if ($elm[type] == 'complete' && preg_match('/(PHENOMENA|PRESSURE|TEMPERATURE|WIND|RELWET|HEAT)/', $elm[tag], $m)) {
        $m = strtolower($m[1]);
        foreach ($elm[attributes] as $key => $val) {
            $data[forecast][$cur_key][$m . '_' . strtolower($key)] = $val;
        }
예제 #3
0
    function show($data, $tpl)
    {
        global $modx;
        $param = $data[forecast][1];
        //icon find
        $ico_precipitation = array(4 => 'rain.png', 5 => 'showers.png', 6 => 'snow.png', 7 => 'snow.png', 8 => 'storm.png');
        $ico_cloudiness = array('clear.png', 'few-clouds.png', 'clouds.png', 'clouds.png');
        $ico = $ico_precipitation[$param[phenomena_precipitation]];
        if (!$ico) {
            //if no precipitations - show cloudiness
            $ico = $ico_cloudiness[$param[phenomena_cloudiness]];
        }
        $translate_path = SNIPPET_PATH . 'translate-' . LANG . '.inc.php';
        if (file_exists($translate_path)) {
            require $translate_path;
        }
        foreach ($param as $k => &$v) {
            $v = isset($translate[$k]) ? Gis::recode('utf-8', MODX_CHARSET, $translate[$k][$v]) : $v;
        }
        $param[town] = $data[town];
        preg_match('/(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)/', $param[date], $m);
        $param[fulldate] = $param[date];
        $param[date] = $m[1] . '.' . $m[2];
        $param[yyyy] = $m[3];
        $param[yy] = substr($m[3], 2);
        $param[dd] = $m[1];
        $param[d] = preg_replace('/^0/', '', $m[1]);
        $param[mm] = $m[2];
        $param[m] = preg_replace('/^0/', '', $m[2]);
        $param[smonth] = Gis::recode('utf-8', MODX_CHARSET, $months[$param[m]]);
        $param[ico] = '/assets/snippets/gismeteo/Tango/' . $ico;
        $default_tpl = <<<HERE
<div class="weather_outer">
\t<img src="[+ico+]" class="w_ico">
\t<div class="w_out_text">
\t\t<div class="w_town">[+town+]</div>
\t\t<div>[+fulldate+], [+weekday+].</div>
\t\t<div class="w_temp">[+temperature_min+]&nbsp;&mdash; [+temperature_max+]&#176;</div>
\t</div>
\t<a href="http://www.gismeteo.ru" class="w_backlink">Предоставлено Gismeteo.Ru</a>
</div>
HERE;
        if ($tpl == 'default') {
            $output = Gis::parse_tpl($default_tpl, $param);
        } else {
            $output = $modx->parseChunk($tpl, $param, '[+', '+]');
        }
        $output = Gis::recode('UTF-8', MODX_CHARSET, $output);
        $modx->regClientCSS($modx->config['base_url'] . 'assets/snippets/gismeteo/Tango/theme.css');
        return $output;
    }
예제 #4
0
    function show($data, $tpl)
    {
        global $modx;
        $translate_path = SNIPPET_PATH . 'translate-' . LANG . '.inc.php';
        if (file_exists($translate_path)) {
            require $translate_path;
        }
        foreach ($data[forecast][1] as $k => &$v) {
            $v = isset($translate[$k]) ? Gis::recode('utf-8', MODX_CHARSET, $translate[$k][$v]) : $v;
        }
        $param = $data[forecast][1];
        $param[town] = $data[town];
        preg_match('/(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)/', $param[date], $m);
        $param[fulldate] = $param[date];
        $param[date] = $m[1] . '.' . $m[2];
        $param[yyyy] = $m[3];
        $param[yy] = substr($m[3], 2);
        $param[dd] = $m[1];
        $param[d] = preg_replace('/^0/', '', $m[1]);
        $param[mm] = $m[2];
        $param[m] = preg_replace('/^0/', '', $m[2]);
        $param[smonth] = Gis::recode('utf-8', MODX_CHARSET, $months[$param[m]]);
        $default_tpl = <<<HERE
<div class="weather_outer">
<div class="w_town">[+town+]</div>
<div>[+weekday+], [+d+] [+smonth+].</div>
<div class="w_temp">[+temperature_min+] - [+temperature_max+]&#176;C</div>
<div>[+phenomena_cloudiness+], [+phenomena_precipitation+]</div>
<a href="http://www.gismeteo.ru" class="weather_backlink">Предоставлено<br>Gismeteo.Ru</a>
</div>
HERE;
        if ($tpl == 'default') {
            $output = Gis::parse_tpl($default_tpl, $param);
        } else {
            $output = $modx->parseChunk($tpl, $param, '[+', '+]');
        }
        $output = Gis::recode('UTF-8', MODX_CHARSET, $output);
        $modx->regClientCSS($modx->config['base_url'] . 'assets/snippets/gismeteo/Text/theme.css');
        return $output;
    }