[solved] Sunrise-Sunset block
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexAdd-Ons & Blocks
Author Message
warden
Silver Supporter


Joined: Dec 16, 2004
Posts: 196
Location: North Carolina

PostPost subject: [solved] Sunrise-Sunset block
Posted: Sun Oct 16, 2011 10:21 am
Reply with quote

I am trying to create a block to display the Sunrise and Sunset information for a site that I maintain. I currently have this quoted code displayed in a file called block-Sunrise-Sunset.php and placed in the /block folder. The information displays but it is not in a block location but rather it displays in the top left hand corner of the website above the header area.

This is the code:
- obsolete code removed -

The output is displayed in this manner:
- img removed -

I have also tried adding
Quote:
if (!defined('CPG_NUKE')) { exit; }
by commenting it out while removing ?> at the end of the file, but this made no change.

Any ideas on why it will not display correctly? Thanks.

_________________


warden's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
NanoCaiordo
Developer


Joined: Jun 29, 2004
Posts: 3678
Location: Melbourne, AU

PostPost subject: Re: Sunrise-Sunset block
Posted: Sun Oct 16, 2011 10:47 am
Reply with quote

PHP:
<?php
if (!defined('CPG_NUKE')) { exit; }
// Enter your longitude and latitude,
// (use negative longitude value for WEST),
// (use negative latitude value for SOUTH)
// example for Cocoa Florida

$lat = 24.5; // North
$long = -79.32; // West

// note for date_sunrise function,
// Because of daylight savings, the offset changes, so rather than static value...
// set the offset to zero, then use default for date to convert final answer to your timezone
// instead of SUNFUNCS_RET_STRING use SUNFUNCS_RET_TIMESTAMP and take resulting

$offset = 0;
$timezone_rollback = date_default_timezone_get();
date_default_timezone_set('America/New_York');

// Note that twilight is a different zenith variable:
//`Zenith' is the angle that the centre of the Sun makes to a line perpendicular to the Earth's surface.
// The best Overall figure for zenith is 90+(50/60) degrees for true sunrise/sunset
// Civil twilight 96 degrees - Conventionally used to signify twilight
// Nautical twilight 102 degrees - the point at which the horizon stops being visible at sea.
// Astronical twilight at 108 degrees - the point when Sun stops being a source of any illumination.

$zenith=90+50/60;
$twilightzenith=96;

// set time for today
$todayTime=time();

// set time for tomorrow, calculate for next day...
$tomorrowTime=strtotime(date("Y-m-d", time()) . " +1 day");


// today sunrise/sunset
$sunStartTimeStamp=date_sunrise($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset);
$sunStartTime=date("h:i", date_sunrise($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset) );
$sunEndTimeStamp=date_sunset($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset) ;
$sunEndTime=date("h:i", date_sunset($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset) );
// today dusk/dawn
$darkEndTimeStamp=date_sunrise($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset);
$darkEndTime=date("h:i", date_sunrise($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset) );
$darkStartTimeStamp=date_sunset($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset);
$darkStartTime=date("h:i", date_sunset($todayTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset) );

// tomorrow sunrise/sunset
$sunStartTime2=date("h:i", date_sunrise($tomorrowTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset) );
$sunEndTime2=date("h:i", date_sunset($tomorrowTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset) );
// tomorrow dawn/dusk
$darkEndTime2=date("h:i", date_sunrise($tomorrowTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset) );
$darkStartTime2=date("h:i", date_sunset($tomorrowTime, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $twilightzenith, $offset) );




// Determine time and if case today or tomorrow for display
// if now is before sunrise, then show all today
// if now is after sunrise but before sunset, then show sunset/dark today, dawn/sunrise tomorrow
// if now is after darkhour, then show all tomorrow
$content = '';
if (
$todayTime <= $sunStartTimeStamp){
// show all today not tomorrow
// $content .= "<small>";
$content .= "<p>Today, ".date("F j, Y",$todayTime)."</p>";
$content .= "<p>";
$content .= "Dawn: $darkEndTime A.M.";
$content .= "<br>";
$content .= "Sunrise: $sunStartTime A.M.";
$content .= "</p><p>";
$content .= "Sunset: $sunEndTime P.M.";
$content .= "<br>";
$content .= "Dark: $darkStartTime P.M.";
$content .= "</p>";
} elseif (
$todayTime >= $darkStartTimeStamp) {
// show all tomorrow
$content .= "<p>Tomorrow, ".date("F j, Y",$tomorrowTime)."</p>";
$content .= "<p>";
$content .= "Dawn: $darkEndTime2 A.M.";
$content .= "<br>";
$content .= "Sunrise: $sunStartTime2 A.M.";
$content .= "</p><p>";
$content .= "Sunset: $sunEndTime2 P.M.";
$content .= "<br>";
$content .= "Dark: $darkStartTime2 P.M.";
$content .= "</p>";
} else {
// show sunset/dusk for today and dawn/sunrise for tomorrow
$content .= "<p>Today, ".date("F j, Y",$todayTime)."</p>";
$content .= "<p>";
$content .= "Sunset: $sunEndTime P.M.";
$content .= "<br>";
$content .= "Dark: $darkStartTime P.M.";
$content .= "</p>";
$content .= "<p>Tomorrow, ".date("F j, Y",$tomorrowTime)."</p>";
$content .= "<p>";
$content .= "Dawn: $darkEndTime2 A.M.";
$content .= "<br>";
$content .= "Sunrise: $sunStartTime2 A.M.";
$content .= "</p>";
// $content .= "</small>";
}
date_default_timezone_set($timezone_rollback);
?>

In blocks you don't echo directly, but rather you need to save it into $content.

_________________
.:: I met php the 03 December 2003 :: Unforgettable day! ::.

NanoCaiordo's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
MySQL 5.1 / PHP 5.3 / NextGen()
Back to top
View user's profile Visit poster's website
warden
Silver Supporter


Joined: Dec 16, 2004
Posts: 196
Location: North Carolina

PostPost subject: Re: Sunrise-Sunset block
Posted: Sun Oct 16, 2011 11:14 am
Reply with quote

Thanks Nano! It works fine.
_________________


warden's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
NanoCaiordo
Developer


Joined: Jun 29, 2004
Posts: 3678
Location: Melbourne, AU

PostPost subject: Re: Sunrise-Sunset block
Posted: Mon Oct 17, 2011 2:40 am
Reply with quote

Also notice $timezone_rollback Wink
_________________
.:: I met php the 03 December 2003 :: Unforgettable day! ::.

NanoCaiordo's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
MySQL 5.1 / PHP 5.3 / NextGen()
Back to top
View user's profile Visit poster's website
warden
Silver Supporter


Joined: Dec 16, 2004
Posts: 196
Location: North Carolina

PostPost subject: Re: [solved] Sunrise-Sunset block
Posted: Tue Oct 25, 2011 4:42 pm
Reply with quote

I missed that part. Thanks for fixing this code to make it work with DF. I like this block.
_________________


warden's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexAdd-Ons & Blocks All times are GMT
Page 1 of 1


Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

stopsoftwarepatents.eu petition banner
User Info [x]

Welcome Anonymous

Nickname
Password
(Register)

Last CVS commits [x]

Languages [x]

Community [x]

Support for DragonflyCMS in a other languages:

Deutsch
Español

X-links [x]
UltraEdit Browse Happy logo Firefox MySQL PostgreSQL Valid CSS! Valid XHTML 1.0! Unicode Encoded Badge NukeBiz Resources Raven DragonflyCMS Dedicated Now InsideSupport Lampe Berger

Preview theme [x]
Each user can view the site with a different theme.
Themes marked with a * also change the forum look.


You are seeing squares or questionmarks on this page?

All content of this website is copyrighted by the Creative Commons NC-SA
The logos and trademarks used on this site are the property of their respective owners
We are not responsible for comments posted by our users, as they are the property of the poster.
Our server runs on a P3 1.2GHz with 512MB RAM with no accelerators
Support GoPHP5.org
This page generated in 3.3674 seconds with 17 DB Queries in 0.1767 seconds
Memory Usage: 3.1 MB
Interactive software released under GNU GPL, Code Credits, Privacy Policy