Topic: Automatic version checking.

I think this is a must for the future, i see no downside except if this site is down you get a couple of seconds lag on the page.

open admin_index.php
find

                                        <dt>PunBB version</dt>
                                        <dd>
                                                PunBB <?php echo $pun_config['o_cur_version'] ?> - <a href="admin_index.php?action=check_upgrade">Check for upgrade</a><br />
                                                © Copyright 2002, 2003, 2004, 2005 Rickard Andersson
                                        </dd>

replace with

                    <dt>PunBB version</dt>
                    <dd>
                        PunBB <?php echo $pun_config['o_cur_version'] ?><br />
<?php
if (!ini_get('allow_url_fopen'))
    echo 'Unable to check for upgrade since \'allow_url_fopen\' is disabled on this system.<br />';
else {
    $fp = @fopen('http://punbb.org/latest_version', 'r');
    @stream_set_timeout($fp, 1);
    $latest_version = trim(@fread($fp, 16));
    @fclose($fp);
 
    if ($latest_version == '')
        echo 'Check for upgrade failed for unknown reasons.<br />';
 
    $cur_version = str_replace(array('.', 'dev', 'beta', ' '), '', strtolower($pun_config['o_cur_version']));
    $cur_version = (strlen($cur_version) == 2) ? intval($cur_version) * 10 : intval($cur_version);
 
    $latest_version = str_replace('.', '', strtolower($latest_version));
    $latest_version = (strlen($latest_version) == 2) ? intval($latest_version) * 10 : intval($latest_version);
 
    if ($cur_version >= $latest_version)
        echo 'You are running the latest version of PunBB.<br />';
    else
        echo '<strong style="color:red">A new version of PunBB has been released. You should download the latest version at <a href="http://punbb.org/">PunBB.org</a>.</strong><br />';
}
?>
                        © Copyright 2002, 2003, 2004, 2005 Rickard Andersson
                    </dd>
                    <dt>PunBB News</dt>
                    <dd>
<?php
if (!ini_get('allow_url_fopen'))
    echo 'Unable to check for news since \'allow_url_fopen\' is disabled on this system.<br />';
else {
    $fp = @fopen('http://punbb.org/forums/extern.php?action=new&fid=48&show=3', 'r');
    @stream_set_timeout($fp, 1);
    $news = trim(@fread($fp, 1000));
    @fclose($fp);
    if ($news != "") 
        echo "<ul>\n".$news."\n</ul>";
    else
        echo "News is currently unavailable.";
}
?>
                    </dd>

it will show a big red message if theres a new version and also show the latest 3 news items from this forum.

2 (edited by CodeXP 2005-09-07 22:30)

Re: Automatic version checking.

Good idea for those who need it. The only problem is that it'll fail on any PHP versions below 4.3.0 (on win32), and also those without 'allow_url_fopen' enabled.

EDIT: I didn't see that you've already added a check for allow_url_open wink

Re: Automatic version checking.

well people with out it need to change host or upgrade tongue

Re: Automatic version checking.

Connorhd wrote:

well people with out it need to change host or upgrade tongue

Hehe, that's true smile

Re: Automatic version checking.

Well, one downside is that this website will be hit every time someone opens their admin interface. I like the feature, but I'm not sure my host will.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Automatic version checking.

Why do you say it will fail? stream_set_timeout? That's easy enough to get around wink

Re: Automatic version checking.

I'm putting it on the list. Like Smartys said on IRC, the results could be cached for up to 24 hours. That would prevent it resulting in such a huge number of hits on punbb.org.

"Programming is like sex: one mistake and you have to support it for the rest of your life."