[Beta]phpBB3 gWeather 0.0.1

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Ideas Centre
User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Tue Dec 08, 2009 3:25 pm

Well, of course. :oops:

If there's an error it sends us back to weather.php with the error message instead of to index.php...

That isn't very helpful, hm?
Muggins

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Tue Dec 08, 2009 3:37 pm

muggins wrote:Well, of course. :oops:

If there's an error it sends us back to weather.php with the error message instead of to index.php...

That isn't very helpful, hm?
We should be able to change it to the index instead, but how?
Aleichem Shalom,

Doctor Love

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Tue Dec 08, 2009 3:48 pm

You could try changing this bit:

Code: Select all

    /**
              * Lets give them a proper error and shut it down
              * if there is invalid input and send them home
              * @var string
              */
             if ($xml->weather->problem_cause['data'])
             {
                //We wont keep them here to long, maybe 3 seconds, then send them back
                meta_refresh(3, append_sid("{$phpbb_root_path}weather.$phpEx"));
                trigger_error('Google Weather is currently unavailable!');         
             }
          }
To this:

Code: Select all

    /**
              * Lets give them a proper error and shut it down
              * if there is invalid input and send them home
              * @var string
              */
             if ($xml->weather->problem_cause['data'])
             {
                //We wont keep them here to long, maybe 3 seconds, then send them back
                meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
                trigger_error('Google Weather is currently unavailable!');         
             }
          }
Notice that the meta_refresh points to index now instead of weather. I haven't tried it, and I'm sure the error message would botch up something else, but you're on the right track! :)
Muggins

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Tue Dec 08, 2009 4:15 pm

Yes, this might work.

It is a shame that gWeather is written where gWeather is of primary consideration, and the forum is secondary. My members can live without an occasional missed weather report, but they will quit coming to the forum if they cannot access it.

I'll give it a try and wait to see if the index shows up one day without the weather report showing up. Hopefully this won't trigger a different error.
Aleichem Shalom,

Doctor Love

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Tue Dec 08, 2009 4:28 pm

NOPE, the change doesn't work. It makes it crash everytime. I think we need an "ELSE" statement.
Sure would be nice if someone, who knows code, would come into the fray.
muggins wrote:You could try changing this bit:

Code: Select all

    /**
              * Lets give them a proper error and shut it down
              * if there is invalid input and send them home
              * @var string
              */
             if ($xml->weather->problem_cause['data'])
             {
                //We wont keep them here to long, maybe 3 seconds, then send them back
                meta_refresh(3, append_sid("{$phpbb_root_path}weather.$phpEx"));
                trigger_error('Google Weather is currently unavailable!');         
             }
          }
To this:

Code: Select all

    /**
              * Lets give them a proper error and shut it down
              * if there is invalid input and send them home
              * @var string
              */
             if ($xml->weather->problem_cause['data'])
             {
                //We wont keep them here to long, maybe 3 seconds, then send them back
                meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
                trigger_error('Google Weather is currently unavailable!');         
             }
          }
Notice that the meta_refresh points to index now instead of weather. I haven't tried it, and I'm sure the error message would botch up something else, but you're on the right track! :)
Aleichem Shalom,

Doctor Love

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Tue Dec 08, 2009 5:08 pm

:oops:
Muggins

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Wed Dec 09, 2009 4:49 am

This may not be the cure to getting the weather when it is not available, but SO FAR it doesn't get stuck on the error page that requires us to input a location.

Code: Select all

/**
			 * Lets give them a proper error and shut it down
			 * if there is invalid input and send them home
			 * @var string
			 */
			if ($xml->weather->problem_cause['data'])
			{
				//We wont keep them here too long, maybe 5 seconds, then send them back
				meta_refresh(5, append_sid('index'));
				trigger_error('GOOGLE WEATHER IS CURRENTLY UNAVAILABLE. Wait for reload.');			
			}
		}
 
		return $return_array;
 
	}
Notice that we were almost correct with the "{$phpbb_root_path}index.$phpEx" replacement for "{$phpbb_root_path}weather.$phpEx". However, according to the following quote"
acyd burn wrote:ok... i hope i haven't messed too much with the code and everything is still working.
Changes:
- Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed.
- A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added.
Therefore:

Code: Select all

append_sid("{$phpbb_root_path}index.$phpEx")
becomes:

Code: Select all

append_sid('index')

I, also, changed the error text just in case the forum itself wasn't available, corrected a typo, and changed the refresh time to 5 seconds. Now I don't know if this is good or bad coding, but so far it is working.
Aleichem Shalom,

Doctor Love

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Thu Dec 10, 2009 8:23 pm

Thanks, Doc! :D
Muggins

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Thu Dec 10, 2009 11:29 pm

muggins wrote:Thanks, Doc! :D

Ooops ! Apparently not everything is kosher yet. While it is true that most issues cleared up, when I clicked on a link in a post (which opened in a new window), I got a 404 error code when I tried to return to the index. That is when I noticed that the URL address only ended with "index".

Example: http://www.yourDomain.com/phpBB3/index

Well the address obviously needed ".php" appended to it. So I went back into root/includes/classes/google_weather.php and changed the code from 'index' to 'index.php' .

This got my site up and running again. IF I have any more issues I'll report back here.

Note: Just for the record, I have PHP Version 5.2.6
Aleichem Shalom,

Doctor Love

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Thu Dec 10, 2009 11:56 pm

Doctor Love wrote: Ooops ! Apparently not everything is kosher yet.
Funny man! 8-) Thanks for that, too! :mrgreen:
Muggins

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Fri Dec 11, 2009 1:02 am

Funny is good, but what is not funny is that the mod author (topdown) has not been heard from since November 14th. Hey topdown where are you ? Don't leave us to figure this out by ourselves.
Aleichem Shalom,

Doctor Love

Mr_makaveli
Registered User
Posts: 1159
Joined: Sun Oct 26, 2008 3:34 pm

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Mr_makaveli » Fri Dec 11, 2009 10:55 am

hes on sg now maybe he has abandoned this
www.tgzforum.com, a new forum for all types of people

User avatar
Doctor Love
Registered User
Posts: 117
Joined: Sat Jul 24, 2004 12:20 am
Location: USA
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by Doctor Love » Fri Dec 11, 2009 12:12 pm

Okay, I have tried every way to crash gWeather now with the latest change (below code), and I have not been able to do so. I am running 3.0.6 and I have installed 27 mods including "Gallery", "mini_chat", and now gWeather. I have a meta-refresh statement in my "overall_header for every 30 minutes, a 15 second refresh on the mini-chat mod, and apparently a random 5 second refresh statement with gWeather. This mod has now been operating flawlessly for more than 12 hours, which equates to more than 24 auto-refreshes, and even more refreshes from reading and posting topics, etc. . Additionally, not one of my moderators has had another crash due to any error. So I am going to assume (for now) that the following code is stable enough to fix the problem until "topdown" returns or someone else with professional coding experience can make changes.

includes/classes/google_weather.php

Code: Select all

<?php
/**
* @package phpBB gWeather
* @version $Id: google_weather.php 2 2009-07-06 06:11:00Z phpbbxpert $
* @author topdown
* @copyright (c) 2009 topdown, Webmasters United.org
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* this beta version modified by Doctor Love 2009-12-11 07:00:00 to prevent session error,
* and correct typos in the comments.
*/
 
/**
 * Some of this script was * origionally authored by Ashwin Surajbali
 * Grabs weather data from Google.com's weather API and return a nicely formatted array
 * This script is modified from the origional version to benefit use in phpBB3
 * Requires PHP 5 or greater
 *
 * Some code in this script is Copyrighted 2009 by Ashwin Surajbali (http://www.redinkdesign.net).
 * This program is free software; you can redistribute it and/or modify it under the terms of the 
 * GNU General Public License as published by the Free Software Foundation.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY 
 * expressed or implied; not even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

class google_weather{
 

	/**
	 * This var will hold the location to send to Google
	 * 
	 * @var string mixed
	 */
	public $location;
 
	/**
	 * Location of the google weather api
	 *
	 * @var string
	 */
	private $gweather_api_url = 'http://www.google.com/ig/api?weather=';
 
	/**
	 * Storage var for data returned from curl request to the google api
	 *
	 * @var string
	 */
	private $raw_data;
 
	/**
	 * Pull weather information for the location
	 * Weather data is returned in an associative array
	 *
	 * @param int $location
	 * @return array
	 */
	public function get_weather_data($location)
	{
 		/**
 		 * we need this for the error reporting and redirect
 		 * @var phpBB globals
 		 */
		global $phpEx, $phpbb_root_path;
			
		$this->location = $location;
			
 			//This doesn't work so lets dump this and use the phpBB way later
			/*if ($this->enable_cache && !empty($this->cache_path)){
				$this->cache_file = $this->cache_path . '/' . $this->zip;
				return $this->load_from_cache();
			}*/
 
		// build the url
		$this->gweather_api_url = $this->gweather_api_url . $this->location;
 
		if ($this->make_request())
		{
 
			$xml = new SimpleXMLElement($this->raw_data);
 
			$return_array = array();
 
			$return_array['forecast_info']['city'] = $xml->weather->forecast_information->city['data'];
			$return_array['forecast_info']['zip'] = $xml->weather->forecast_information->postal_code['data'];
			$return_array['forecast_info']['date'] = $xml->weather->forecast_information->forecast_date['data'];
			$return_array['forecast_info']['date_time'] = $xml->weather->forecast_information->current_date_time['data'];
 
			$return_array['current_conditions']['condition'] = $xml->weather->current_conditions->condition['data'];
			$return_array['current_conditions']['temp_f'] = $xml->weather->current_conditions->temp_f['data'];
			$return_array['current_conditions']['temp_c'] = $xml->weather->current_conditions->temp_c['data'];
			$return_array['current_conditions']['humidity'] = $xml->weather->current_conditions->humidity['data'];
			$return_array['current_conditions']['icon'] = 'http://www.google.com' . $xml->weather->current_conditions->icon['data'];
			$return_array['current_conditions']['wind'] = $xml->weather->current_conditions->wind_condition['data'];
 
			for ($i = 0; $i < count($xml->weather->forecast_conditions); $i++)
			{
				$data = $xml->weather->forecast_conditions[$i];
				$return_array['forecast'][$i]['day_of_week'] = $data->day_of_week['data'];
				$return_array['forecast'][$i]['low'] = $data->low['data'];
				$return_array['forecast'][$i]['high'] = $data->high['data'];
				$return_array['forecast'][$i]['icon'] = 'http://img0.gmodules.com/' . $data->icon['data'];
				$return_array['forecast'][$i]['condition'] = $data->condition['data'];
			}
 			
			/**
          * Lets give them a proper error and shut it down
          * if there is invalid input and send them home
          * @var string
          */
         if ($xml->weather->problem_cause['data'])
         {
            //We wont keep them here too long, maybe 5 seconds, then send them back
            meta_refresh(5, append_sid('index.php'));
            trigger_error('GOOGLE WEATHER IS CURRENTLY UNAVAILABLE.');         
         }
      }

      return $return_array;

   }
 
	private function make_request()
	{
 
		$ch = curl_init();
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_URL, $this->gweather_api_url);
		curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		$this->raw_data = curl_exec ($ch);
		curl_close ($ch);
 
		if (empty($this->raw_data))
		{
			return false;
			
		}
		else
		{
			return true;
		}
 
	}
 
}
 
?>
In no way am I assuming control over this mod.
Aleichem Shalom,

Doctor Love

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: [Beta]phpBB3 gWeather 0.0.1

Post by muggins » Sat Dec 12, 2009 1:06 am

Happy Hanukkah! :D
Muggins

SLAMO
Registered User
Posts: 15
Joined: Wed Apr 09, 2008 9:54 am

Re: [Beta]phpBB3 gWeather 0.0.1

Post by SLAMO » Thu Dec 17, 2009 9:02 pm

Hi,
where can I find the MOD subsilver2?
Thx

Locked

Return to “[3.0.x] MODs in Development”