Exemplo n.º 1
0
 /**
  * Convert the raw XML into an object
  *
  * @param \SimpleXMLElement $xml
  * @return Gis
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $gis = new Gis();
     if (isset($xml->xcoordinate)) {
         $gis->setXCoordinate((double) $xml->xcoordinate);
     }
     if (isset($xml->ycoordinate)) {
         $gis->setYCoordinate((double) $xml->ycoordinate);
     }
     return $gis;
 }
Exemplo n.º 2
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;
    }
 public static function rewrite_cache($source, $timemark, $region, $updates)
 {
     global $modx;
     $cachemark = Gis::cachemark($timemark, $region);
     $fh = fopen(BASE_PATH . $modx->getCachePath() . '/gismeteo' . $cachemark . '.xml', 'w');
     fwrite($fh, $source);
     fclose($fh);
     foreach ($updates as $time) {
         if ($time == $timemark) {
             continue;
         }
         $mark = Gis::cachemark($time, $region);
         $path = BASE_PATH . $modx->getCachePath() . '/gismeteo' . $mark . '.xml';
         if (file_exists($path)) {
             unlink($path);
         }
     }
 }
Exemplo n.º 4
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;
    }
Exemplo n.º 5
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;
    }