[FIXED] from PHP 4 to PHP 5 (error in xml data)

Easy to use and free Joomla module to display weather with forecast from Yahoo.
Rate this topic: Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.
manuel_84
Wed Jul 14, 2010 9:51 pm
The module display this error if I have PHP5 instead of PHP4

Code: Select all
An error occured during parsing XML data.
User avatar
Fresh Boarder

Seichinha
Thu Jul 15, 2010 12:06 am
Hi

Please check if you have cURLS extension enable on your php.ini file.

Find

Code: Select all
;extension=php_curl.dll


and change to

Code: Select all
extension=php_curl.dll


Contact your host provider if you don't have access.

Also it's fundamental that you set full permissions (777) for cache directory and for file mod_gk_weather.xml

Cheers
User avatar
Moderator

manuel_84
Thu Jul 15, 2010 12:31 am
Seichinha wrote:
Hi

Please check if you have cURLS extension enable on your php.ini file.

Find

Code: Select all
;extension=php_curl.dll


and change to

Code: Select all
extension=php_curl.dll


Contact your host provider if you don't have access.

Also it's fundamental that you set full permissions (777) for cache directory and for file mod_gk_weather.xml

Cheers


yes I already have full permissions and the curl extension enabled :dry:
User avatar
Fresh Boarder

Seichinha
Thu Jul 15, 2010 2:19 am
Are you sure you have 777 permissions on mod_gk_weather.xml? :huh:

What version of joomla and PHP version are u using?
(Be objective on which version of PHP5)
User avatar
Moderator

manuel_84
Thu Jul 15, 2010 12:18 pm
Seichinha wrote:
Are you sure you have 777 permissions on mod_gk_weather.xml? :huh:

What version of joomla and PHP version are u using?
(Be objective on which version of PHP5)


Yes I am sure!
I have Joomla 1.5.18 (latest) and PHP 5.2.13 with cURL support enabled (libcurl/7.20.1 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5)

I think that the problem might be on this line (helper.php)
Code: Select all
$current_conditions = $xml->document->weather[0]->current_conditions[0];


Seems that Joomla JSimpleXMLElement does not return the same values switching from php 4 to 5

I will investigate. Sorry for my poor english :)
User avatar
Fresh Boarder

manuel_84
Thu Jul 15, 2010 12:31 pm
Yes, with PHP5 the JFactory XML Parser return a different XML structure.
See the output for $xml->document (I can't paste here, it's too long), I cannot see humidity and wind conditions when parsing ($xml->loadString($this->content)) this reply:

Code: Select all
<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information><city data="Cabras, Sardinia"/><postal_code data="Cabras,Sardinia"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2010-07-15"/><current_date_time data="2010-07-15 09:55:00 +0000"/><unit_system data="SI"/></forecast_information><current_conditions><condition data="Parzialmente nuvoloso"/><temp_f data="88"/><temp_c data="31"/><humidity data="Umidit?: 79%"/><icon data="/ig/images/weather/partly_cloudy.gif"/><wind_condition data="Vento: E a 19 km/h"/></current_conditions><forecast_conditions><day_of_week data="gio"/><low data="22"/><high data="29"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Chiaro"/></forecast_conditions><forecast_conditions><day_of_week data="ven"/><low data="23"/><high data="31"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Chiaro"/></forecast_conditions><forecast_conditions><day_of_week data="sab"/><low data="23"/><high data="30"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Chiaro"/></forecast_conditions><forecast_conditions><day_of_week data="dom"/><low data="21"/><high data="28"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Chiaro"/></forecast_conditions></weather></xml_api_reply>
User avatar
Fresh Boarder

manuel_84
Thu Jul 15, 2010 1:01 pm
OMG I've found it! :side:

When you parse the XML response ($xml->loadString($this->content)) if it contains invalid non-xml characters like
Code: Select all
<humidity data="Umidit[color=#BF0000]?[/color]: 79%"/>
the resulting JSimpleXML object does not contains the relative object (humidity in this case) and

I have solved the problem temporarily changing the language from "it" (with accents) to "en" (without accents) :S

GK Weather must convert invalid characters from the google response into xml valid content-encoding to definitively solve this problem!
User avatar
Fresh Boarder

manuel_84
Thu Jul 15, 2010 2:45 pm
SOLUTION B)

open helper.php and add these 2 functions:

Code: Select all
 function XMLEntities($string)
    {
        $string = preg_replace('/[^x09x0Ax0Dx20-x7F]/e', '$this->_privateXMLEntities("$0")', $string);
        return $string;
    }

    function _privateXMLEntities($num)
    {
    $chars = array(
        128 => '&#8364;',
        130 => '&#8218;',
        131 => '&#402;',
        132 => '&#8222;',
        133 => '&#8230;',
        134 => '&#8224;',
        135 => '&#8225;',
        136 => '&#710;',
        137 => '&#8240;',
        138 => '&#352;',
        139 => '&#8249;',
        140 => '&#338;',
        142 => '&#381;',
        145 => '&#8216;',
        146 => '&#8217;',
        147 => '&#8220;',
        148 => '&#8221;',
        149 => '&#8226;',
        150 => '&#8211;',
        151 => '&#8212;',
        152 => '&#732;',
        153 => '&#8482;',
        154 => '&#353;',
        155 => '&#8250;',
        156 => '&#339;',
        158 => '&#382;',
        159 => '&#376;');
        $num = ord($num);
        return (($num > 127 && $num < 160) ? $chars[$num] : "&#".$num.";" );
    }


find

Code: Select all
if($xml->loadString($this->content))


replace

Code: Select all
if($xml->loadString($this->XMLEntities($this->content)))
User avatar
Fresh Boarder

teitbite
Thu Jul 15, 2010 2:49 pm
Hi

Great :) Thank You for Your help.
User avatar
Moderator

manuel_84
Thu Jul 15, 2010 2:53 pm
teitbite wrote:
Hi

Great :) Thank You for Your help.


you are welcome :)
I am testing and improving the code right now... think I will post some updates soon
User avatar
Fresh Boarder

manuel_84
Thu Jul 15, 2010 4:14 pm
see file attached, this is the final version

tested on php 4 and 5 and with english and italian language, we should check other encoding and languages
Attachments
helper-20100715.zip
(3.98 KiB) Downloaded 97 times
User avatar
Fresh Boarder

manuel_84
Fri Jul 16, 2010 11:55 pm
are you planning a new bugfixed release ?
User avatar
Fresh Boarder

luciffere
Thu Jul 22, 2010 1:58 pm
I have same problem. When i checked the modules/mod_gk_weather/cache/mod_gk_weather.xml i found this:

Code: Select all
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://sorry.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DCraiova,%2520RO%26hl%3Dro">here</A>.
</BODY></HTML>
.

I deteted, saved and again.
In front-end the module show:
Warning: filesize() [function.filesize]: stat failed for /var/www/cache/mod_gk_weather.xml in /var/www/modules/mod_gk_weather/helper.php on line 182
An error occured during parsing XML data. Please try again.


I downloaded the helper.php from thispost but nothing.

LE. On localhost work, but online not. I have curl enabled: curl
cURL support enabled
cURL Information libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1

The modules/mod_gk_weather/cache/ is 777 and modules/mod_gk_weather/cache/mod_gk_weather.xml same 777
Can see the website: http://www.mercurcraiova.ro
User avatar
Fresh Boarder

luciffere
Thu Jul 22, 2010 4:22 pm
Now work, but behind the module is shown this error:

Warning: filesize() [function.filesize]: stat failed for /var/www/cache/mod_gk_weather.xml in /var/www/modules/mod_gk_weather/helper.php on line 136


LE: Now work... i changed owner for modules/mod_gk_weather/cache/mod_gk_weather.xml and copy the modules/mod_gk_weather/cache/mod_gk_weather.xml file in cache/mod_gk_weather/mod_gk_weather.xml

In back-end at language i changed ro-RO in ro... and disable cache function.
User avatar
Fresh Boarder

manuel_84
Fri Jul 30, 2010 4:52 pm
today Google has changed url?

Code: Select all
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://sorry.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DCabras,Sardinia%26hl%3Dit">here</A>.

</BODY></HTML>



please, update GK Weather to fix latest problems!
User avatar
Fresh Boarder

uhecht
Sun Aug 01, 2010 2:12 pm
Got the same problems with that module on my website. Where can I edit and update my module. Have got another website with the same module and it works - computer are crazy ;-)

Thanks for your support.

uhecht
User avatar
Senior Boarder

uhecht
Sun Aug 01, 2010 5:54 pm
Solution again

helper.php

Find www.google.con ... and replace it with www.google.de

And it works!

BUT: It only works in English. So far so good- but on a German website something strange. If I change en->de inside the module configuration all ä,ü, ö and so on are not printed in German.

However, it works quite normal and maybe there's a hint to print it in default German as I want.

uhecht
User avatar
Senior Boarder

manuel_84
Sun Aug 01, 2010 6:05 pm
sometimes google can block your site for too many requests and gk weather displays the xml error
you can check this condition reading /modules/mod_gk_weather/cache mod_gk_weather.xml
User avatar
Fresh Boarder


cron
Remember me
Don't have an account?
GavickPro website uses cookies. By continuing to use this website, you are giving consent to cookies being used. More details…×