Skip to content

Commit

Permalink
Improve output.
Browse files Browse the repository at this point in the history
Show localized dates, fix double colons, and improve Horde_View syntax.
  • Loading branch information
yunosh committed Jan 12, 2016
1 parent 22c3705 commit 8c433e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
13 changes: 9 additions & 4 deletions horde/lib/Block/Weather.php
Expand Up @@ -115,16 +115,18 @@ protected function _params()
*/
protected function _content()
{
global $injector, $page_output, $prefs;

// Set the requested units.
$this->_weather->units = $this->_params['units'];
$view = $GLOBALS['injector']->getInstance('Horde_View');
$view = $injector->getInstance('Horde_View');

if (!empty($this->_refreshParams) && !empty($this->_refreshParams->location)) {
$location = $this->_refreshParams->location;
$view->instance = '';
} else {
$view->instance = hash('md5', mt_rand());
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(
$injector->getInstance('Horde_Core_Factory_Imple')->create(
'WeatherLocationAutoCompleter',
array(
'id' => 'location' . $view->instance,
Expand Down Expand Up @@ -154,6 +156,9 @@ protected function _content()
$view->station = $this->_weather->getStation();
$view->current = $this->_weather->getCurrentConditions($view->location->code);
// @todo: Add link to put alert text in redbox.
$view->timezone = $prefs->getValue('timezone');
$view->dateFormat = $prefs->getValue('date_format');
$view->timeFormat = $prefs->getValue('time_format');
$view->alerts = $this->_weather->getAlerts($view->location->code);
$view->radar = $this->_weather->getRadarImageUrl($location);
} catch (Horde_Service_Weather_Exception $e) {
Expand All @@ -162,9 +167,9 @@ protected function _content()

if (!empty($this->_params['showMap']) && !empty($view->instance)) {
$view->map = true;
$GLOBALS['page_output']->addScriptFile('weatherblockmap.js', 'horde');
$page_output->addScriptFile('weatherblockmap.js', 'horde');
Horde_Core_HordeMap::init(array('providers' => array('owm', 'osm')));
$GLOBALS['page_output']->addInlineScript(array(
$page_output->addInlineScript(array(
'WeatherBlockMap.initializeMap("' . $view->instance . '", { lat: "' . $view->location->lat . '", lon: "' . $view->location->lon . '"});$("weathermaplayer_' . $view->instance . '").show();'
), true);
}
Expand Down
25 changes: 18 additions & 7 deletions horde/templates/block/weather_content.html.php
Expand Up @@ -7,14 +7,25 @@

<div class="horde-content">
<!-- Weather alerts -->
<?php if (!empty($this->alerts)):
foreach ($this->alerts as $alert): ?>
<div class="hordeWeather<?php echo (!empty($this->sig) ? $this->sig : 'Alert')?>" title="<?php echo $this->h($alert['body'])?>">
<div style="font-weight:bold;"><?php echo $this->h($alert['desc'])?></div>
<?php if (!empty($alert['date_text'])):?><strong><?php echo _("Starts: ")?>:</strong> <?php echo $this->h($alert['date_text'])?><br /><?php endif; ?><strong><?php echo _("Expires: ")?></strong>: <?php echo $alert['expires_text']?>
<?php if (!empty($this->alerts)): ?>
<?php foreach ($this->alerts as $alert): ?>
<div class="hordeWeather<?php echo (!empty($this->sig) ? $this->sig : 'Alert') ?>" title="<?php echo $this->h($alert['body']) ?>">
<div style="font-weight:bold;"><?php echo $this->h($alert['desc']) ?></div>
<?php if (!empty($alert['date'])): ?>
<?php $alert['date']->setTimezone($this->timezone); ?>
<strong><?php echo _("Starts:") ?></strong> <?php echo $this->h($alert['date']->strftime($this->dateFormat . ' ' . $this->timeFormat)) ?><br />
<?php elseif (!empty($alert['date_text'])): ?>
<strong><?php echo _("Starts:") ?></strong> <?php echo $this->h($alert['date_text']) ?><br />
<?php endif ?>
<?php if (!empty($alert['expires'])): ?>
<?php $alert['expires']->setTimezone($this->timezone); ?>
<strong><?php echo _("Expires:") ?></strong> <?php echo $this->h($alert['expires']->strftime($this->dateFormat . ' ' . $this->timeFormat)) ?><br />
<?php elseif (!empty($alert['expires_text'])): ?>
<strong><?php echo _("Expires:") ?></strong> <?php echo $this->h($alert['expires_text']) ?>
<?php endif ?>
</div>
<?php endforeach;?>
<?php endif;?>
<?php endforeach ?>
<?php endif ?>

<!-- Sunrise/Sunset -->
<?php if ($this->station->sunrise):?>
Expand Down

0 comments on commit 8c433e0

Please sign in to comment.