TorrentFlux.com Welcome, Guest. Please login or register.
01-06-2009, 13:49:30
Home Help Search Login Register donate
TorrentFlux Home | TorrentFlux Hosting

+  TorrentFlux Forums
|-+  Code Hacks and Tools
| |-+  TorrentFlux 2.1 Hacks
| | |-+  Page Refresh Countdown Timer
« previous next »
Pages: [1] Go Down Print
Author Topic: Page Refresh Countdown Timer  (Read 7866 times)
steveholt
Jr. Member
**
Offline Offline

TF Base: Linux 2.x
Posts: 72


Debian Packager





View Profile WWW
« on: 04-07-2006, 17:49:07 »

This hack will change the "*** Page Will Refresh Every 60 Seconds ***" message at the bottom of the main page into a countdown timer to 0, at which point the page refreshes. I like to know how fresh the data I'm seeing is, especially if I've set a longer timer (like 10 minutes).

All the changes are in the main index.php file only. I'll describe them here, but I've also attached a patch that should work on an unmodified index.php file.

In the <head>, where it says:
Code:
<?php
    if(!isset($_SESSION['prefresh']) || ($_SESSION['prefresh'] == true))
    {
        echo "<meta http-equiv=\"REFRESH\" content=\"".$cfg["page_refresh"].";URL=index.php\">";
    }
?>
Add in the lines to make it say:
Code:
<?php
    if(!isset($_SESSION['prefresh']) || ($_SESSION['prefresh'] == true))
    {
        echo "<meta http-equiv=\"REFRESH\" content=\"".$cfg["page_refresh"].";URL=index.php\">";
?>
<script language="JavaScript">
    var var_refresh = <?php echo $cfg["page_refresh"] ?>;
    function UpdateRefresh() {
        span_refresh.innerHTML = String(var_refresh--);
        setTimeout("UpdateRefresh();", 1000);
    }
</script>
<?php
    }
?>

Change the line:
Code:
<body topmargin="8" bgcolor="<?php echo $cfg["main_bgcolor"] ?>">
to:
Code:
<body onLoad="UpdateRefresh();" topmargin="8" bgcolor="<?php echo $cfg["main_bgcolor"] ?>">

And finally, change the line:
Code:
        echo "*** "._PAGEWILLREFRESH." ".$cfg["page_refresh"]." "._SECONDS." ***<br>";
to:
Code:
        echo "*** "._PAGEWILLREFRESH." <span id='span_refresh'>".$cfg["page_refresh"]."</span> "._SECONDS." ***<br>";

That's it, now when you load the front page it should count down from 60 (or whatever your refresh timer is) down to 0, at which point the page should refresh. It's pretty simple, though it could be made better by updating _PAGEWILLREFRESH in the language file to say "Page Will Refresh In" instead of "Page Will Refresh Every".

Enjoy!
Logged

AthlonXP 2400+ | 3x300GB | 512MB RAM | Debian Testing | TF 2.3 | Python 2.4.4 | Apache 2.2.3 | PHP 5.2.0 (module)
ryaner
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 919





View Profile
« Reply #1 on: 04-07-2006, 17:53:16 »

Nice hack and good idea too.
Logged

SERVER: Debian Sarge 2.6.16| AMD XP2000+ | 1.5GB Ram  | 1.6T - Raid 5 | TF 2.1 | Apache 2.0.54 | PHP 4.3.10 | MySQL 4.1.11 | Mod/Hacks: XFER Transfer Stats/Multi Torrent Delete/Seed Time Hack/Ajax Details/Torrent Details/RSS Hack
Qrome
Administrator
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 2784


TorrentFlux.com





View Profile
« Reply #2 on: 04-07-2006, 18:21:51 »

Thanks Cameron, that is a good idea.
Logged

Check out the new FireFox Extension by IceWind for TorrentFlux called TorrentFlux Add -- right click on torrents and have them added to your TorrentFlux list.
Bandi
Jr. Member
**
Offline Offline

TF Base: Linux 2.x
Posts: 87



View Profile
« Reply #3 on: 04-07-2006, 23:51:28 »

Really Perfekt Smiley
Logged
coldfire
Jr. Member
**
Offline Offline

Posts: 64






View Profile
« Reply #4 on: 04-08-2006, 01:24:24 »

Nice idea, well done!
Logged

Gentoo 2005-r1, TF 2.1 final + Specific Save Path, Multi-Upload and Page Refresh Countdown Timer hacks, 120GB dedicated to TF
Qrome
Administrator
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 2784


TorrentFlux.com





View Profile
« Reply #5 on: 04-08-2006, 02:41:00 »

This will be in the next release or update.
Logged

Check out the new FireFox Extension by IceWind for TorrentFlux called TorrentFlux Add -- right click on torrents and have them added to your TorrentFlux list.
greenhorn
Newbie
*
Offline Offline

Posts: 3






View Profile
« Reply #6 on: 04-08-2006, 07:30:32 »

very nice and quite simple thx
Logged
gringo
Full Member
***
Offline Offline

TF Base: Linux 1.x
Posts: 110





View Profile WWW
« Reply #7 on: 04-08-2006, 16:44:22 »

Simple but awesome hack.  Good thinking.
Logged

P4 2.8 | CentOS-4.2 | 1024MB RAM | 10 mb/s Connect

Apache 2.0.52 | PHP 4.3.9 | MySQL 4.1.12 | Python 2.3.4

TF 2.1b4rt with cosmetic changes.
lord_nor
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 173




View Profile
« Reply #8 on: 04-10-2006, 12:16:31 »

I like this hack very much, however, I have noticed one thing that's a little odd. If a refresh takes longer than usual to start, the countdown keeps on going down into the negatives. This has happened several times that I've noticed on my server (new RAM is on the way). Not really an issue, but whatever.
Logged

If they give you lined paper, write the other way.

Freebsd 6.1 | PHP 5.1.4 | MySql 5.1.9-beta | Apache 1.3.36
steveholt
Jr. Member
**
Offline Offline

TF Base: Linux 2.x
Posts: 72


Debian Packager





View Profile WWW
« Reply #9 on: 04-10-2006, 12:58:56 »

Yeah, that doesn't really surprise me. The refresh timer and the actual page refresh are handled separately, and aren't really linked. So, if your browser counts down too slowly/quickly, the page will refresh before/after the timer reaches zero. Mine has never gone negative, but I have noticed that if I'm doing something on another tab and come back, then the count is off and the page refreshes before the timer reaches zero.

I'll try to link the two, so the page always refreshes at zero. I'll use JavaScript to do the page refresh, instead of using the meta http-equiv REFRESH method. That probably affects non-JS people though (if they exist), so I'll keep the meta hhtp-equiv method as a backup.

Try changing the first block to this (1 new line):
Code:
<?php
    if(!isset($_SESSION['prefresh']) || ($_SESSION['prefresh'] == true))
    {
        echo "<meta http-equiv=\"REFRESH\" content=\"".$cfg["page_refresh"].";URL=index.php\">";
?>
<script language="JavaScript">
    var var_refresh = <?php echo $cfg["page_refresh"] ?>;
    function UpdateRefresh() {
        if (var_refresh == 0) { window.location.reload( true ); }
        span_refresh.innerHTML = String(var_refresh--);
        setTimeout("UpdateRefresh();", 1000);
    }
</script>
<?php
    }
?>

That should make it never go negative, though it might still refresh before the timer reaches zero. Since mine never goes negative I can't really be sure this solves it, so let me know if it fixes your problem lord_nor.
Logged

AthlonXP 2400+ | 3x300GB | 512MB RAM | Debian Testing | TF 2.3 | Python 2.4.4 | Apache 2.2.3 | PHP 5.2.0 (module)
weedfan
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 8





View Profile
« Reply #10 on: 08-19-2006, 17:34:56 »

Thank you for the hack!

Where is the
Code:
$cfg["page_refresh"]
variable defined?

It displayes *** Page Will Refresh Every <countdown> Seconds ***

I would like to change it to *** Page Will Refresh In <countdown> Seconds ***

I assume it is in one of the .js files but I couldn't find it.  It's not in the database either.

Thanks,
Logged

weedfan
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #11 on: 08-20-2006, 15:13:40 »

language/lang-english.php or your language:]
look for:
define("_PAGEWILLREFRESH","Page Will Refresh In");
Logged

weedfan
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 8





View Profile
« Reply #12 on: 08-23-2006, 21:54:23 »

Thank you!!
Logged

weedfan
luke
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 29




View Profile
« Reply #13 on: 10-05-2006, 10:34:52 »

thanks  Grin
Logged

osearth
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 9




View Profile
« Reply #14 on: 10-29-2006, 17:37:45 »

thx we were just about to write this mod, your work is appreciated!!
Logged

Many servers my personal ones are mostly:
FreeBSD 6.1-RELEASE  ||  Apache/1.3.36 (Unix)  ||  PHP Version 5.1.4  ||  MySQL 3.23.59  ||  Python 2.2.3  ||
Pages: [1] Go Up Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by SMF 1.1.1 | SMF © 2006, Simple Machines LLC Powered by PHP