Page 1 of 5

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

Posted: 17. November 2008 19:39
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.

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

Posted: 18. November 2008 07:01
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!

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

Posted: 18. November 2008 17:37
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?

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

Posted: 18. November 2008 20:31
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

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

Posted: 18. November 2008 22:42
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" />

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

Posted: 18. November 2008 23:10
by GoldStarDad
Here is a screen shot of the Center Block on Gold Star Dads

Image

Thanks Kevin

michael

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

Posted: 19. November 2008 11:02
by Kevin
Moved to "Released Blocks" :)

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

Posted: 20. November 2008 07:50
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

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

Posted: 21. November 2008 22:58
by Kevin
Just modify the profile field and the template file (HTML code) to your needs.

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

Posted: 22. November 2008 06:10
by shahinavthal
Done !! thanks a lot :mrgreen:

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

Posted: 25. November 2008 06:52
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.

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

Posted: 25. November 2008 08:10
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

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

Posted: 25. November 2008 08:16
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

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

Posted: 25. November 2008 10:52
by Kevin
I guess you haven't set up the custom profile field correctly.

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

Posted: 26. November 2008 02:41
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.