[EN] Weatherforecast with User ZIP code (weather.com)

Forum rules
This forum is not for support requests.

Only post Modifications for Board3 Portal 1.0.x in this forum.
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

[EN] Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

Ads a block, displaying the weather forecast for the region of the users, detected by the user ZIP code.
weather_forecast_block.gif
Every single user can add his ZIP code in a custom profile field in the UCP. A standard ZIP code, if a user have not set his ZIP code, could be set within the code.

Preparation:

You need to add a "custom profile field" in the ACP for this block. This can be found in the ACP --> "users and groups".
  • Create new field
    • Field identification: zip_code
    • Field type: Single text field
    • Field identification: No
    • Display in user control panel: Yes
    • Display in user control panel: Weather forecast ZIP code
    • Field description: Enter your ZIP Code, if you want to have a weather forecast of your region displayed on the portal.
  • Profile type specific options
    • Length of input box: 5
    • Minimum number of characters: 5
    • Maximum number of characters: 5
    • Field validation: Only numbers (0-9)
This is how we give the opportunity to enter the ZIP code for the users and get it into the database.

Now the file changes:
Open: portal.php
search:

Code: Select all

if ($portal_config['portal_pay_s_block'] or ( $portal_config['portal_pay_c_block'] && $load_center === TRUE ) )
{
    include($phpbb_root_path . 'portal/block/donate.'.$phpEx);
}   
add after:

Code: Select all

// Weather START
    include($phpbb_root_path . 'portal/block/weather.'.$phpEx);
// Wether END                                       
Create a new file, named weather.php and upload it to portal/block/
Content:

Code: Select all

<?php

    if (!defined('IN_PHPBB'))
    {
       exit;
    }

    if (!defined('IN_PORTAL'))
    {
       exit;
    }

            $sql = "SELECT pf_zip_code
                FROM " . PROFILE_FIELDS_DATA_TABLE . "
                WHERE user_id = " . $user->data['user_id'];

            $result = $db->sql_query_limit($sql, 1);
            $zip_code     = $db->sql_fetchfield('pf_zip_code');
            $db->    sql_freeresult($result);

        $template->assign_vars(array(
            'WEATHER_ZIP'     => (!empty($zip_code)) ? $zip_code : '92557', // Change 20099 to the wished default ZIP code
        ));

    ?>
Please replace the 20099 with the default ZIP Code for the region that should be displayed, if a user has not set his ZIP code in the UCP or a guest is viewing the portal.
  • Prosilver:
    • Open: styles/prosilver/template/portal/portal_body.html
      search:

      Code: Select all

      <!-- IF S_DISPLAY_WELCOME -->
                  <!-- IF S_DISPLAY_WELCOME_GUEST and S_USER_LOGGED_IN -->
                  <!-- ELSE -->
                      <!-- INCLUDE portal/block/welcome.html -->
                  <!-- ENDIF -->
              <!-- ENDIF --> 
      add after (or at the wished position):

      Code: Select all

              <!-- Weather Start -->
                  <!-- INCLUDE portal/block/weather.html -->
              <!-- Weather End -->   
      Cerate a new file in styles/prosilver/template/portal/block/ named weather.html, containing:

      Code: Select all

          <div class="forabg">
             <div class="inner">
                <span class="corners-top"><span></span></span>
                <ul class="topiclist">
                   <li class="header"><dl><dt>Weather Forecast for Region: {WEATHER_ZIP}</dt></dl></li>
                </ul>
                <ul class="topiclist forums">
                   <li><dl>
                      <dd class="posts_portal"  style="border-left:0px">
      <div style='width: 728px; height: 90px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/hurricane_728x90_bg.jpg ); background-repeat: no-repeat; background-color: #0F243A;' ><div style='height: 74px;' ><script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2.asp?partner=netweather&tStyle=dark2&logo=1&zipcode={WEATHER_ZIP}&lang=eng&size=11&theme=hurricane&metric=0&target=_self'></script></div><div style='text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 11px; line-height: 16px; color: #FDEA11;' ><img style='float: right; padding-right: 5px;' src='http://vortex.accuweather.com/adc2004/common/images/misc/netweather_v2/adcwhite.png' /></div></div>
                      </div>
                      </dd>
                   </dl></li>
                </ul>
                <span class="corners-bottom"><span></span></span>
             </div>
          </div>
          <br style="clear:both" />

  • subsilver2:
    • Open: styles/subsilver2/template/portal/portal_body.html
      search:

      Code: Select all

      <!-- IF S_DISPLAY_WELCOME -->
                  <!-- IF S_DISPLAY_WELCOME_GUEST and S_USER_LOGGED_IN -->
                  <!-- ELSE -->
                      <!-- INCLUDE portal/block/welcome.html -->
                  <!-- ENDIF -->
              <!-- ENDIF --> 
      add after (or at wished position:

      Code: Select all

              <!-- Weather Start -->
                  <!-- INCLUDE portal/block/weather.html -->
              <!-- Weather End -->    

      Create a new file in styles/subsilver2/template/portal/block/ named weather.html, containing:

      Code: Select all

      <table class="tablebg" cellspacing="1" width="100%">
      <tr class="row1">
          <th>Weather Forecast for Region: {WEATHER_ZIP}</th>
      </tr>
      <tr>
          <td class="row1">
              <table width="100%" cellspacing="0" cellpadding="0" border="0">
              <tr>
                  <td>
                          <div style='width: 728px; height: 90px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/hurricane_728x90_bg.jpg ); background-repeat: no-repeat; background-color: #0F243A;' ><div style='height: 74px;' ><script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2.asp?partner=netweather&tStyle=dark2&logo=1&zipcode={WEATHER_ZIP}&lang=eng&size=11&theme=hurricane&metric=0&target=_self'></script></div><div style='text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 11px; line-height: 16px; color: #FDEA11;' ><img style='float: right; padding-right: 5px;' src='http://vortex.accuweather.com/adc2004/common/images/misc/netweather_v2/adcwhite.png' /></div></div>
                  </td>
              </tr>
              </table>
          </td>
      </tr>
      </table>
      <br />


The variable {WEATHER_ZIP} could be used for other services too. Just adapt the code in the template file as needed.
Thats it - have fun.

Please note: this is not tested. Please get back to me with the results.
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

Updated, using "accuweather.com"
Seems to be easier, as no account have to be created.

Please get back to me with your testing results!
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

the.ronin
Valued Contributor
Posts: 64
Joined: 30. October 2008 16:20

Re: Weatherforecast with User ZIP code (weather.com)

Post by the.ronin »

Oh very cool. This may dovetail well with the surf forecast block you helped me out with Kevin!!

Can you do a screenshot of what weather info it shows? And I can accomodate this in a small side block?
User avatar

GoldStarDad
Active Member
Posts: 11
Joined: 3. November 2008 19:44

Re: Weatherforecast with User ZIP code (weather.com)

Post by GoldStarDad »

Kevin,

YOU ARE THE MAN! Works like a charm.

I made a few minor changes to the code just for better output.

I already had a Zip Code function set up in custom profile fields so I just made these changes to weather.php;

Code: Select all

   <?php

    if (!defined('IN_PHPBB'))
    {
       exit;
    }

    if (!defined('IN_PORTAL'))
    {
       exit;
    }

            $sql = "SELECT pf_zip_code
                FROM " . PROFILE_FIELDS_DATA_TABLE . "
                WHERE user_id = " . $user->data['user_id'];

            $result = $db->sql_query_limit($sql, 1);
            $zip_code     = $db->sql_fetchfield('pf_zip_code');
            $db->    sql_freeresult($result);

        $template->assign_vars(array(
            'WEATHER_ZIP'     => (!empty($zip_code)) ? $zip_code : '92557', // Change 20099 to the wished default ZIP code
        ));

    ?>
That made it pull from my current data with out a new field.

The second fix was to CHANGE SERVICES to AccuWeather. Much better choice of displays. Her is the code change I worked out after a few trial & error (I'm no Code Junkie so these were mostly errors on my part) This gives you a nice 728x90 center block. Here is the weather.html

Code: Select all

   <div class="forabg">
           <div class="inner">
              <span class="corners-top"><span></span></span>
              <ul class="topiclist">
                 <li class="header"><dl><dt>Weather Forecast for Region: {WEATHER_ZIP}</dt></dl></li>
              </ul>
              <ul class="topiclist forums">
                 <li><dl>
                    <dd class="posts_portal"  style="border-left:0px">
                    <div style="text-align: left; margin: 5px 5px 5px 5px">
                     

<div style='width: 728px; height: 90px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/hurricane_728x90_bg.jpg ); background-repeat: no-repeat; background-color: #0F243A;' ><div style='height: 74px;' ><script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2.asp?partner=netweather&tStyle=dark2&logo=1&zipcode={WEATHER_ZIP}&lang=eng&size=11&theme=hurricane&metric=0&target=_self'></script></div><div style='text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 11px; line-height: 16px; color: #FDEA11;' ><img style='float: right; padding-right: 5px;' src='http://vortex.accuweather.com/adc2004/common/images/misc/netweather_v2/adcwhite.png' /></div></div>
                    </div>
                    </dd>
                 </dl></li>
              </ul>
              <span class="corners-bottom"><span></span></span>
           </div>
        </div>
        <br style="clear:both" />
That's it, your code was GREAT!

Thank You
Michael
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

GoldStarDad wrote:Works like a charm.

I made a few minor changes to the code just for better output.
Fantastic! :)
Thank you - i've updated the first post.
the.ronin wrote:Can you do a screenshot of what weather info it shows?
Michael, would you mind to add a screenshot of the block? I don't use this block, so I'm not able to. ;)
the.ronin wrote:Oh very cool. This may dovetail well with the surf forecast block you helped me out with Kevin!!
Yar, correct. :mrgreen:
the.ronin wrote:And I can accomodate this in a small side block?
Sure. You can see a demo (in German, the block called "Wetter"), here: http://www.ostpocken.de/portal.php
You can use this code for several purposes, where you want to use infos, the users have set in the UCP.
Just set up a custom profile field, change the names in the code and use it.
For a small side block (with Michaels weather service) the code would like like this:

Code: Select all

        <div class="portal-panel">
            <div class="inner">
                <span class="portal-corners-top"><span></span></span>
                    <h3><img src="{T_THEME_PATH}/images/portal/portal_statistic.gif" width="18px" height="18px" alt=""/>&nbsp;Weather</h3>
                    <div style="text-align: center;">
                        <!-- Weathercode Start -->
                      <div style='width: 728px; height: 90px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/hurricane_728x90_bg.jpg ); background-repeat: no-repeat; background-color: #0F243A;' ><div style='height: 74px;' ><script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2.asp?partner=netweather&tStyle=dark2&logo=1&zipcode={WEATHER_ZIP}&lang=eng&size=11&theme=hurricane&metric=0&target=_self'></script></div><div style='text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 11px; line-height: 16px; color: #FDEA11;' ><img style='float: right; padding-right: 5px;' src='http://vortex.accuweather.com/adc2004/common/images/misc/netweather_v2/adcwhite.png' /></div></div>
                        <!-- Weathercode End -->
                    </div>
                    <br />
                <span class="portal-corners-bottom"><span></span></span>
            </div>
        </div>
        <br style="clear:both" />
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!
User avatar

GoldStarDad
Active Member
Posts: 11
Joined: 3. November 2008 19:44

Re: Weatherforecast with User ZIP code (weather.com)

Post by GoldStarDad »

Here is a screen shot of the Center Block on Gold Star Dads

Image

Thanks Kevin

michael
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

Moved to "Released Blocks" :)
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

shahinavthal
Active Member
Posts: 2
Joined: 20. November 2008 07:46
phpBB.com User: shahinavthal

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by shahinavthal »

Wonderful looking block..But can you please make it search the Accuweather based on International City etc other than ZIPCODE because we dont have zipcode facilities here

I would like to link --> http://www.accuweather.com/world-index- ... E005|DUBAI

Thanks a lot
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

Just modify the profile field and the template file (HTML code) to your needs.
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

shahinavthal
Active Member
Posts: 2
Joined: 20. November 2008 07:46
phpBB.com User: shahinavthal

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by shahinavthal »

Done !! thanks a lot :mrgreen:

ccotton
Active Member
Posts: 3
Joined: 15. October 2008 20:38

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by ccotton »

This is a great block, but I must have messed up the coding. I'm having the following problems:
  • 1. The weather defaults to St. College, PA;
    2. The Zip Code does not appear after the phrase "Weather Forecast for Region: "
    3. The Zip Code entered into the user profile is not accepted; and
    4. The weather block doesn't cover the entire block on the page.
I'm testing it on a very small board I run before moving it to an active board. It is a http://www.TexasIDPA.com Do you have any suggestions where I may have messed up the code?

Thanks,
Chas.
User avatar

GoldStarDad
Active Member
Posts: 11
Joined: 3. November 2008 19:44

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by GoldStarDad »

chas, it seems you have other problems as well. You have an extra /www/ in your address when you try to load ANY of your forums. Somewhere you have to remove a "/" also I don't see any field for your zip code in the registration form. Did you remember to refresh templates and dump your cache?

Michael
User avatar

GoldStarDad
Active Member
Posts: 11
Joined: 3. November 2008 19:44

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by GoldStarDad »

This is the error message when you try to open the forum to try and get the secret code to register. I suggest that you give the answer on the registration page such as The answer to this security question is "abc123" The whole purpose of the security question is to stop spam bots is it not? they cant read.

Here is that error message

Parse error: syntax error, unexpected '}' in /home/texasidpa/www/www/cache/tpl_prosilver_viewforum_body.html.php on line 143

Michael
User avatar

Topic author
Kevin
Site Admin
Posts: 2989
Joined: 7. January 2006 20:11
phpBB.de User: Saint
phpBB.com User: Saint_hh
Location: Hamburg
Contact:

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by Kevin »

I guess you haven't set up the custom profile field correctly.
~~~ They say the definition of madness is doing the same thing and expecting a different result ~~~

Kein Support per PN / No support via PM!

ccotton
Active Member
Posts: 3
Joined: 15. October 2008 20:38

Re: [EN] Weatherforecast with User ZIP code (weather.com)

Post by ccotton »

Thanks guys, I must have really screwed up something. I restored backup files and I'll start over. I'm glad I didn't start on my big board first!

Thanks again,
Chas.
Locked

Return to “board3 Portal v1.0.x - Modifications”