MoreBloodWine
02-10-2011, 11:48 AM
** Note of interest as to not get anyone here in a hissy... It was suggested that I put this post here, so this is not a double post compared to my post in the JS board. **
1) Project Details: Check out turtle-tv.com
Notice the (Lights on/off ...) stuff above the chat and ustream windows. I would like to have it turned in to a live ticker that updates without needing to refrsh the page. It currently runs off of server time which is how I'd like it to stay.
So lets say the current time was 7:29:59am
The message in the parenthesis would read (Lights on in 1 Sec)
Then come 7:30am the message would read...
(Lights off in 12 Hrs, 30 Mins)
Ok, so you should now get the idea of how it works so I don't need an example of what it would read come 7:59:59pm etc etc etc.
2) Payment Amount: Negotiable
3) Payment Method: PayPal
4) Timeline: Done when it's done (no rush)
5) Additional Info:
The first block of code is what produces everything you see at turtle-tv.com...
The second block is something OldPedant hooked me up with a while back for a different project and is what I would like to have worked in since it's good, usable code. Obviously certain things will need to be removed / omitted since it doesnt apply to this project like the $contestend stuff and the bit that would display when the counter reaches 0.
Block 1
<?php
$lights_on = '7:30am';
$lights_off = '8pm';
$time = lights_on_off(time(), $lights_on, $lights_off);
?>
<head>
<title>Niko's Live 24/7 Video Broadcast</title>
</head>
<body background="./smalls_file_mainBg_1919366_7636654_l.jpg">
<font size="2" color="FFFF00" style="background: #181818;">Time Now: <?php echo date('g:ia'); ?></font>
<center>
<font size="5" color="FFFF00" style="background: #181818;">
Lights out from <?php echo $lights_off; ?> to <?php echo $lights_on; ?> <?php echo date('T'); ?>
(Lights <?php echo $time['n_state']; ?> in
<?php
$h = ($time['remaining']['m'] + 1 ==60) ? $time['remaining']['h'] + 1 : $time['remaining']['h'];
$m = ($time['remaining']['m'] + 1 ==60) ? 0 : $time['remaining']['m'];
$s = ($time['remaining']['m'] + 1 ==60) ? 0 : $time['remaining']['s'];
echo ($h>1) ? $h . ' Hrs, ' : (($h==1) ? $h . ' Hr, ' : ' ');
echo ($m>1) ? $m . ' Mins & ' : (($m==1) ? $m . ' Min & ' : ' ');
echo ($s>1) ? $s . ' Secs' : (($s==1) ? $s . ' Sec' : '0 Secs');
?>
) !
</font></center>
<?php
function lights_on_off($time, $lights_on, $lights_off){
$time = (isset($time)) ? $time : time();
$d_lights_on = strtotime($lights_on);
$d_lights_off = strtotime($lights_off);
$secs_lights_on = (date("G",$d_lights_on)*60 + date("i",$d_lights_on))*60 + date("s",$d_lights_on);
$secs_lights_off = (date("G",$d_lights_off)*60 + date("i",$d_lights_off))*60 + date("s",$d_lights_off);
$secs = (date("G",$time)*60 + date("i",$time))*60 + date("s",$time);
$c_state = ($secs_lights_on < $secs && $secs < $secs_lights_off) ? 'on' : 'off';
$n_state = ($secs_lights_on < $secs && $secs < $secs_lights_off) ? 'off' : 'on';
$next_switch = ($secs_lights_on < $secs && $secs_lights_off > $secs) ? $secs_lights_off : ($secs_lights_on + 60*60*24);
$next_switch = ($next_switch > ($secs+60*60*24)) ? $next_switch - (60*60*24) : $next_switch;
$time_rem = $next_switch - $secs;
$h = floor($time_rem/(60*60));
$m = floor(($time_rem-($h*60*60))/60);
$s = $time_rem-($h*60*60)-($m*60);
return array('c_state' => $c_state,'n_state' => $n_state, 'remaining' => array('secs' => $next_switch, 'h' => $h, 'm' => $m, 's' => $s));
}
?>
<center>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="523" id="utv451302">
<param name="flashvars" value="autoplay=false&brand=embed&cid=1919366"/><param name="allowfullscreen" value="true"/>
<param name="allowscriptaccess" value="always"/><param name="movie" value="http://www.ustream.tv/flash/live/1/1919366"/>
<embed flashvars="autoplay=false&brand=embed&cid=1919366" width="625" height="545" allowfullscreen="true" allowscriptaccess="always"
id="utv451302" name="utv_n_740840" src="http://www.ustream.tv/flash/live/1/1919366" type="application/x-shockwave-flash" /></object>
<iframe scrolling="no" height="523" frameborder="0" width="576" src="./prochatrooms/index.php"></iframe>
</center>
</body>
Block 2a
<script type="text/javascript">
var curTime = <?php time() ?>;
var endTime = <?php $contestend ?>;
var tock = null;
function tick( )
{
var msg = "";
var secs = endTime - curTime;
++curTime;
if ( secs <= 0 )
{
clearInterval(tock);
document.getElementById("remain").innerHTML = "------- Sorry, but this contest ended on <?php echo date('D. F jS, Y', strftime($contestend)); ?> -------";
return;
}
var show = false;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
if ( days > 0 ) show = true;
if ( show ) msg += days + ( days != 1 ? " Days, " : " Day, " );
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
if ( hrs > 0 ) show = true;
if ( show ) msg += hrs + ( hrs != 1 ? " Hrs, " : " Hr, " );
secs %= 3600;
var mins = Math.floor( secs / 60 );
if ( mins > 0 ) show = true;
if ( show ) msg += mins + ( mins != 1 ? " Mins & " : " Min & " );
secs %= 60;
msg += secs + ( secs != 1 ? " Secs " : " Sec " );
var t = document.getElementById("ticker");
t.innerHTML = msg;
if ( ! show ) t.style.color = "red";
}
</script>
Block 2b (Not really needed since it's the display aspect but posting for the sake of completeness...)
<span id="ticker">Loading...</span>
Ps: One other thing that would obviously need to be omitted is the red text upon the final second being passed... since this will be a continual clock with roll over between lights on and off.
I'm guessing thats easily enough solved just by removing the below line of code...
if ( ! show ) t.style.color = "red";
1) Project Details: Check out turtle-tv.com
Notice the (Lights on/off ...) stuff above the chat and ustream windows. I would like to have it turned in to a live ticker that updates without needing to refrsh the page. It currently runs off of server time which is how I'd like it to stay.
So lets say the current time was 7:29:59am
The message in the parenthesis would read (Lights on in 1 Sec)
Then come 7:30am the message would read...
(Lights off in 12 Hrs, 30 Mins)
Ok, so you should now get the idea of how it works so I don't need an example of what it would read come 7:59:59pm etc etc etc.
2) Payment Amount: Negotiable
3) Payment Method: PayPal
4) Timeline: Done when it's done (no rush)
5) Additional Info:
The first block of code is what produces everything you see at turtle-tv.com...
The second block is something OldPedant hooked me up with a while back for a different project and is what I would like to have worked in since it's good, usable code. Obviously certain things will need to be removed / omitted since it doesnt apply to this project like the $contestend stuff and the bit that would display when the counter reaches 0.
Block 1
<?php
$lights_on = '7:30am';
$lights_off = '8pm';
$time = lights_on_off(time(), $lights_on, $lights_off);
?>
<head>
<title>Niko's Live 24/7 Video Broadcast</title>
</head>
<body background="./smalls_file_mainBg_1919366_7636654_l.jpg">
<font size="2" color="FFFF00" style="background: #181818;">Time Now: <?php echo date('g:ia'); ?></font>
<center>
<font size="5" color="FFFF00" style="background: #181818;">
Lights out from <?php echo $lights_off; ?> to <?php echo $lights_on; ?> <?php echo date('T'); ?>
(Lights <?php echo $time['n_state']; ?> in
<?php
$h = ($time['remaining']['m'] + 1 ==60) ? $time['remaining']['h'] + 1 : $time['remaining']['h'];
$m = ($time['remaining']['m'] + 1 ==60) ? 0 : $time['remaining']['m'];
$s = ($time['remaining']['m'] + 1 ==60) ? 0 : $time['remaining']['s'];
echo ($h>1) ? $h . ' Hrs, ' : (($h==1) ? $h . ' Hr, ' : ' ');
echo ($m>1) ? $m . ' Mins & ' : (($m==1) ? $m . ' Min & ' : ' ');
echo ($s>1) ? $s . ' Secs' : (($s==1) ? $s . ' Sec' : '0 Secs');
?>
) !
</font></center>
<?php
function lights_on_off($time, $lights_on, $lights_off){
$time = (isset($time)) ? $time : time();
$d_lights_on = strtotime($lights_on);
$d_lights_off = strtotime($lights_off);
$secs_lights_on = (date("G",$d_lights_on)*60 + date("i",$d_lights_on))*60 + date("s",$d_lights_on);
$secs_lights_off = (date("G",$d_lights_off)*60 + date("i",$d_lights_off))*60 + date("s",$d_lights_off);
$secs = (date("G",$time)*60 + date("i",$time))*60 + date("s",$time);
$c_state = ($secs_lights_on < $secs && $secs < $secs_lights_off) ? 'on' : 'off';
$n_state = ($secs_lights_on < $secs && $secs < $secs_lights_off) ? 'off' : 'on';
$next_switch = ($secs_lights_on < $secs && $secs_lights_off > $secs) ? $secs_lights_off : ($secs_lights_on + 60*60*24);
$next_switch = ($next_switch > ($secs+60*60*24)) ? $next_switch - (60*60*24) : $next_switch;
$time_rem = $next_switch - $secs;
$h = floor($time_rem/(60*60));
$m = floor(($time_rem-($h*60*60))/60);
$s = $time_rem-($h*60*60)-($m*60);
return array('c_state' => $c_state,'n_state' => $n_state, 'remaining' => array('secs' => $next_switch, 'h' => $h, 'm' => $m, 's' => $s));
}
?>
<center>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="523" id="utv451302">
<param name="flashvars" value="autoplay=false&brand=embed&cid=1919366"/><param name="allowfullscreen" value="true"/>
<param name="allowscriptaccess" value="always"/><param name="movie" value="http://www.ustream.tv/flash/live/1/1919366"/>
<embed flashvars="autoplay=false&brand=embed&cid=1919366" width="625" height="545" allowfullscreen="true" allowscriptaccess="always"
id="utv451302" name="utv_n_740840" src="http://www.ustream.tv/flash/live/1/1919366" type="application/x-shockwave-flash" /></object>
<iframe scrolling="no" height="523" frameborder="0" width="576" src="./prochatrooms/index.php"></iframe>
</center>
</body>
Block 2a
<script type="text/javascript">
var curTime = <?php time() ?>;
var endTime = <?php $contestend ?>;
var tock = null;
function tick( )
{
var msg = "";
var secs = endTime - curTime;
++curTime;
if ( secs <= 0 )
{
clearInterval(tock);
document.getElementById("remain").innerHTML = "------- Sorry, but this contest ended on <?php echo date('D. F jS, Y', strftime($contestend)); ?> -------";
return;
}
var show = false;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
if ( days > 0 ) show = true;
if ( show ) msg += days + ( days != 1 ? " Days, " : " Day, " );
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
if ( hrs > 0 ) show = true;
if ( show ) msg += hrs + ( hrs != 1 ? " Hrs, " : " Hr, " );
secs %= 3600;
var mins = Math.floor( secs / 60 );
if ( mins > 0 ) show = true;
if ( show ) msg += mins + ( mins != 1 ? " Mins & " : " Min & " );
secs %= 60;
msg += secs + ( secs != 1 ? " Secs " : " Sec " );
var t = document.getElementById("ticker");
t.innerHTML = msg;
if ( ! show ) t.style.color = "red";
}
</script>
Block 2b (Not really needed since it's the display aspect but posting for the sake of completeness...)
<span id="ticker">Loading...</span>
Ps: One other thing that would obviously need to be omitted is the red text upon the final second being passed... since this will be a continual clock with roll over between lights on and off.
I'm guessing thats easily enough solved just by removing the below line of code...
if ( ! show ) t.style.color = "red";