(#1)
c0rrupt Offline
Administrator
 
Posts: 192
Join Date: Mar 2010
Location: Canada
Updated: TIME ago - 11-07-2010, 10:27 AM

by jomasaco on Mon Jul 12, 2010

To show an msg like Updated: 2 minutes ago, 1hour....

Code:
    <?php
    /*BEGIN_INFO
    Show  the last time updated.
    END_INFO*/
    if(!defined("WCDDL_GUTS")) exit;
        $modEnabled = true; //Change to false if don't use
        if($modEnabled) {
    function formatar_tempo($timeBD) { //Script feito por: Túlio Spuri
        $timeNow = time();
        $timeRes = $timeNow - $timeBD;
        $nar = 0;
        // variável de retorno
        $r = "";
        // Agora
        if ($timeRes == 0){
            $r = "Now";
        } else
        // Segundos
        if ($timeRes > 0 and $timeRes < 60){
            $r = $timeRes. " seconds ago";
        } else
        // Minutos
        if (($timeRes > 59) and ($timeRes < 3599)){
            $timeRes = $timeRes / 60;    
            if (round($timeRes,$nar) >= 1 and round($timeRes,$nar) < 2){
                $r = round($timeRes,$nar). " minute ago";
            } else {
                $r = round($timeRes,$nar). " minutes ago";
            }
        }
         else
        // Horas
        // Usar expressao regular para fazer hora e MEIA
        if ($timeRes > 3559 and $timeRes < 85399){
            $timeRes = $timeRes / 3600;
            if (round($timeRes,$nar) >= 1 and round($timeRes,$nar) < 2){
                $r = round($timeRes,$nar). " hour ago";
            }
            else {
                $r = round($timeRes,$nar). " hours ago";        
            }
        } else
        // Dias
        // Usar expressao regular para fazer dia e MEIO
        if ($timeRes > 86400 and $timeRes < 2591999){
            $timeRes = $timeRes / 86400;
            if (round($timeRes,$nar) >= 1 and round($timeRes,$nar) < 2){
                $r = round($timeRes,$nar). " days ago";
            } else {
                preg_match('/(\d*)\.(\d)/', $timeRes, $matches);
                if ($matches[2] >= 5) {
                    $ext = round($timeRes,$nar) - 1;
                    // Imprime o dia
                    $r = $ext;
                    // Formata o dia, singular ou plural
                    if ($ext >= 1 and $ext < 2){ $r.= " day "; } else { $r.= " days ";}
                    // Imprime o final da data
                    $r.= "½ ago";
                } else {
                    $r = round($timeRes,0) . " days ago";
                }
            }
        }
        return $r;
    }
            $ip = $_SERVER['REMOTE_ADDR'];
            $sql = 'SELECT dat FROM wcddl_downloads WHERE id = (select Max(id)from wcddl_downloads)';
            $result = mysql_query($sql);
            $row = mysql_fetch_assoc($result);
            $lastime = $row[dat];
    $updatedtime = '[*]Updated: '.formatar_tempo($lastime);
    $core->setTemplateVar("updatetime",$updatedtime);
    }
    ?>


Before doing any edits to your DDL Site always make a BACKUP first.

Bookmarks

Tags
ago, time, updated

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Powered by vBulletin


Content Relevant URLs by vBSEO