[EN] Weatherforecast with User ZIP code (weather.com)
Posted: 17. November 2008 19:39
Ads a block, displaying the weather forecast for the region of the users, detected by the user ZIP code.
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".
Now the file changes:
Open: portal.php
search:
add after:
Create a new file, named weather.php and upload it to portal/block/
Content:
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.
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.
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)
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);
}
Code: Select all
// Weather START
include($phpbb_root_path . 'portal/block/weather.'.$phpEx);
// Wether END
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
));
?>
- Prosilver:
- Open: styles/prosilver/template/portal/portal_body.html
search:add after (or at the wished position):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 -->
Cerate a new file in styles/prosilver/template/portal/block/ named weather.html, containing:Code: Select all
<!-- Weather Start --> <!-- INCLUDE portal/block/weather.html --> <!-- Weather End -->
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" />
- Open: styles/prosilver/template/portal/portal_body.html
- subsilver2:
- Open: styles/subsilver2/template/portal/portal_body.html
search:add after (or at wished position: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 -->
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 />
- Open: styles/subsilver2/template/portal/portal_body.html
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.