This fixes a problem where the condition text would have more than 1 condition like: "Cloudy/Windy"
Also it introduces the translation words "Rain" and "Wind".
in your language file you should add (according to your languages used):
MOD_WEATHER_GK4_RAIN="Rain"
MOD_WEATHER_GK4_WIND="Wind"
Another thing which is addressed in conjunction with 'Wind" is the double-colon which was in the language file: "Wind:". I moved the double-colon into the code.
Hope this helps
- Code: Select all
Index: modules/mod_weather_gk4/helper.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/mod_weather_gk4/helper.php (revision )
+++ modules/mod_weather_gk4/helper.php (revision )
@@ -160,8 +160,10 @@
"Rain/Snow Showers" => JText::_('MOD_WEATHER_GK4_RAIN_SNOW_SHOWERS'),
"PM Rain/Snow Showers" => JText::_('MOD_WEATHER_GK4_PM_RAIN_SNOW_SHOWERS'),
"Light Snow" => JText::_('MOD_WEATHER_GK4_LIGHT_SNOW'),
- "Snow Showers Late" => JText::_('MOD_WEATHER_GK4_SNOW_SHOWERS_LATE')
+ "Snow Showers Late" => JText::_('MOD_WEATHER_GK4_SNOW_SHOWERS_LATE'),
+ "Rain" => JText::_('MOD_WEATHER_GK4_RAIN'),
+ "Wind" => JText::_('MOD_WEATHER_GK4_WIND')
-
+
);
// parsed from XML data
$this->parsedData = array(
@@ -212,7 +214,7 @@
// initializing connection
$curl = curl_init();
// saves us before putting directly results of request
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// url to get
// check the source of request
if($this->config['source'] == 'google'){
@@ -257,7 +259,7 @@
// initializing connection
$curl = curl_init();
// saves us before putting directly results of request
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// url to get
$encoding_url = ($this->config['encoding'] != '') ? '&oe='.$this->config['encoding'] : '';
// check the source of query
@@ -294,7 +296,7 @@
function parseData() {
if($this->error === '') {
// checking for 400 Bad request page
- if(strpos($this->content, '400 Bad') == FALSE) {
+ if(strpos($this->content, '400 Bad') == false) {
$xml =& JFactory::getXMLParser('Simple');
if($this->config['source'] == 'google'){
if($xml->loadString($this->content)) {
@@ -360,7 +362,7 @@
- if(strpos($xml->document->channel[0]->description[0]->attributes('date'), "Error") == FALSE) {
+ if(strpos($xml->document->channel[0]->description[0]->attributes('date'), "Error") == false) {
$problem = false;
$current_info = $xml->document->channel[0];
$current_info2 = $xml->document->channel[0]->item[0];
@@ -374,21 +376,32 @@
isset($current_info->wind[0])
) {
// loading data from feed
- if(isset($this->translation[$current_info2->condition[0]->attributes('text')])){
- $this->parsedData['current_condition'] = $this->translation[$current_info2->condition[0]->attributes('text')];
+
+
+ $conditionText=$current_info2->condition[0]->attributes('text');
+
+ $conditionResult = $this->processConditionText($conditionText);
+ if(isset($conditionResult)){
+ $this->parsedData['current_condition'] = $conditionResult;
} else {
- $this->parsedData['current_condition'] = $current_info2->condition[0]->attributes('text');
+ $this->parsedData['current_condition'] = $current_info2->condition[0]->attributes('text');
}
$this->parsedData['current_temp'] = $current_info2->condition[0]->attributes('temp')."°".$current_info->units[0]->attributes('temperature');
$this->parsedData['current_humidity'] = JText::_('MOD_WEATHER_GK4_HUMIDITY') ." " .$current_info->atmosphere[0]->attributes('humidity')."%";
$this->parsedData['current_icon'] = $current_info2->condition[0]->attributes('code');
- $this->parsedData['current_wind'] = JText::_('MOD_WEATHER_GK4_WIND') ." ".$current_info->wind[0]->attributes('speed')." ".$current_info->units[0]->attributes('speed');
+ $this->parsedData['current_wind'] = JText::_('MOD_WEATHER_GK4_WIND') .": ".$current_info->wind[0]->attributes('speed')." ".$current_info->units[0]->attributes('speed');
$this->parsedData['sunrise'] = $current_info->astronomy[0]->attributes('sunrise');
$this->parsedData['sunset'] = $current_info->astronomy[0]->attributes('sunset');
// parsing forecast
for($i = 0; $i < 2; $i++) {
- if(isset($this->translation[$forecast_info->forecast[$i]->attributes('text')])){
- $this->cond_tmp = $this->translation[$forecast_info->forecast[$i]->attributes('text')];
+
+ $conditionText=$forecast_info->forecast[$i]->attributes('text');
+
+
+ $conditionResult = $this->processConditionText($conditionText);
+
+ if(isset($conditionResult)){
+ $this->cond_tmp = $conditionResult;
} else {
$this->cond_tmp = $forecast_info->forecast[$i]->attributes('text');
}
@@ -401,7 +414,7 @@
);
}
} else {
- $problem = true; // set the problem
+ $problem = true; // set the problem
$this->error = 'An error occured during parsing XML data. Please try again.';
}
// if problem detected
@@ -423,7 +436,35 @@
}
}
}
+
- /**
+ /**
+ * Processes condition text
+ * It takes into account slashes when multiple conditions are defined
+ *
+ * @param $conditionText
+ *
+ * @return string
+ */
+ public function processConditionText($conditionText)
+ {
+ if (isset($conditionText)) {
+ $explodedCondition = explode("/", $conditionText);
+ $conditionResult = '';
+ foreach ($explodedCondition as $conditionKey => $conditionTextValue) {
+ if ($conditionKey > 0) {
+ $conditionResult = $conditionResult . '/';
+ }
+ $conditionResult = $conditionResult . $this->translation[$conditionTextValue];
+ }
+
+ return $conditionResult;
+ }
+
+ return;
+ }
+
+
+ /**
* RENDERING LAYOUT
**/
function renderLayout() {
@@ -556,7 +597,7 @@
$f_date = date("Y-m-d")." ".$time;
$pos = strpos($f_date, "pm");
$f_date = preg_replace('/ [a-z][a-z]/', ':00', $f_date);
- return strtotime($f_date) + (($pos !== FALSE) ? 12*3600 : 0); // if pm add 12 hours
+ return strtotime($f_date) + (($pos !== false) ? 12*3600 : 0); // if pm add 12 hours
}
/*
* function to parse Celsius to Farhenheit
\ No newline at end of file