Changeset 1291 in ExiteCMS


Ignore:
Timestamp:
02/19/08 22:26:25 (4 years ago)
Author:
hverton
Message:

added datediff() function which returns the difference between two timestamps in text
updated the wikilink detection code in parsemessage()
added a "vertical-align:text-top" to the imagelink smarty function, to align the image properly

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/administration/tools/language_pack_English.php

    r1281 r1291  
    25072507        $localestrings['065'] = "Not a member yet?<br /><a href='%sregister.php' class='side'>Click here</a> to register."; 
    25082508        $localestrings['066'] = "Forgotten your password?<br />Request a new one <a href='%slostpassword.php' class='side'>here</a>."; 
     2509        $localestrings['070'] = "Online"; 
     2510        $localestrings['071'] = "< 5 mins"; 
     2511        $localestrings['072'] = "week"; 
     2512        $localestrings['073'] = "weeks"; 
     2513        $localestrings['074'] = "day"; 
     2514        $localestrings['075'] = "days"; 
     2515        $localestrings['076'] = "month"; 
     2516        $localestrings['077'] = "months"; 
     2517        $localestrings['078'] = "year"; 
     2518        $localestrings['079'] = "years"; 
    25092519        $localestrings['080'] = "Edit Profile"; 
    25102520        $localestrings['081'] = "Private Messages"; 
  • trunk/files/locales/en.main.global.php

    r1281 r1291  
    33// locale       : English 
    44// locale name  : main.global 
    5 // generated on : Thu Feb 14 2008, 15:05:23 CET 
     5// generated on : Mon Feb 18 2008, 14:35:18 CET 
    66// translators  : ExiteCMS team,WanWizard 
    77// ---------------------------------------------------------- 
     
    6565$locale['065'] = "Not a member yet?<br /><a href='%sregister.php' class='side'>Click here</a> to register."; 
    6666$locale['066'] = "Forgotten your password?<br />Request a new one <a href='%slostpassword.php' class='side'>here</a>."; 
     67$locale['070'] = "Online"; 
     68$locale['071'] = "< 5 mins"; 
     69$locale['072'] = "week"; 
     70$locale['073'] = "weeks"; 
     71$locale['074'] = "day"; 
     72$locale['075'] = "days"; 
     73$locale['076'] = "month"; 
     74$locale['077'] = "months"; 
     75$locale['078'] = "year"; 
     76$locale['079'] = "years"; 
    6777$locale['080'] = "Edit Profile"; 
    6878$locale['081'] = "Private Messages"; 
  • trunk/includes/core_functions.php

    r1269 r1291  
    746746} 
    747747 
    748 // Translate bytes into kb, mb, gb or tb by CrappoMan 
     748 
     749// translate a timestamp into a date relative to now 
     750function datediff($datefrom,$dateto=-1) 
     751{ 
     752    global $locale; 
     753     
     754    // validate parameters 
     755    if ($datefrom == 0) { return ""; } 
     756    if ($dateto == -1) { $dateto = time(); } 
     757 
     758    // calculate the difference in seconds betweeen the two timestamps 
     759    $difference = $dateto - $datefrom; 
     760 
     761    // determine the interface 
     762    if ($difference < 60) { 
     763        // if difference is less than 60 seconds, seconds is a good interval of choice 
     764        $interval = "h"; 
     765    } elseif ($difference >= 60 && $difference<60*60) { 
     766        // if difference is between 60 seconds and 60 minutes, minutes is a good interval 
     767      $interval = "h"; 
     768    } elseif ($difference >= 60*60 && $difference<60*60*24) { 
     769        // if difference is between 1 hour and 24 hours, hours is a good interval 
     770        $interval = "h"; 
     771    } elseif ($difference >= 60*60*24 && $difference<60*60*24*7) { 
     772        // if difference is between 1 day and 7 days, days is a good interval 
     773        $interval = "d"; 
     774    } elseif ($difference >= 60*60*24*7 && $difference < 60*60*24*30) { 
     775        // if difference is between 1 week and 30 days, weeks is a good interval 
     776        $interval = "w"; 
     777    } elseif ($difference >= 60*60*24*30 && $difference < 60*60*24*365) { 
     778        // if difference is between 30 days and 365 days, months is a good interval, again, the same thing 
     779        // applies, if the 29th February happens to exist between your 2 dates, the function will return 
     780        // the 'incorrect' value for a day 
     781        $interval = "m"; 
     782    } elseif ($difference >= 60*60*24*365) { 
     783        // if difference is greater than or equal to 365 days, return year. This will be incorrect if 
     784        // for example, you call the function on the 28th April 2008 passing in 29th April 2007. It will 
     785        // return 1 year ago when in actual fact (yawn!) not quite a year has gone by 
     786        $interval = "y"; 
     787    } 
     788 
     789    // based on the interval, determine the number of units between the two dates 
     790    // from this point on, you would be hard pushed telling the difference between 
     791    // this function and DateDiff. If the $datediff returned is 1, be sure to return 
     792    // the singular of the unit, e.g. 'day' rather 'days' 
     793    $res = ""; 
     794    switch($interval) { 
     795        case "w": 
     796            $datediff = floor($difference / 60 / 60 / 24 / 7); 
     797            $res = $datediff . " " . (($datediff==1) ? $locale['072'] : $locale['073']); 
     798            break; 
     799 
     800        case "y": 
     801            $datediff = floor($difference / 60 / 60 / 24 / 365); 
     802            $res = $datediff . " " . (($datediff==1) ? $locale['078'] : $locale['079']); 
     803            break; 
     804 
     805        case "m": 
     806            $months_difference = floor($difference / 60 / 60 / 24 / 29); 
     807            while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) { 
     808                $months_difference++; 
     809            } 
     810            $datediff = $months_difference; 
     811            // we need this in here because it is possible to have an 'm' interval and a months 
     812            // difference of 12 because we are using 29 days in a month 
     813            if ($datediff==12) { 
     814                $datediff--; 
     815            } 
     816            $res .= $datediff . " " . (($datediff==1) ? $locale['076'] : $locale['077']); 
     817            break; 
     818 
     819        case "d": 
     820            $datediff = floor($difference / 60 / 60 / 24); 
     821            $res .= $datediff . " " . (($datediff==1) ? $locale['074'] : $locale['075']); 
     822            break; 
     823 
     824        case "h": 
     825            $datediff = floor($difference / 60 / 60); 
     826            $res .= sprintf("%02d:", $datediff); 
     827 
     828        case "n": 
     829            $datediff = floor($difference / 60); 
     830            $res .= sprintf("%02d:", $datediff); 
     831 
     832        case "s": 
     833            $datediff = $difference; 
     834            $res .= sprintf("%02d", $datediff); 
     835            break; 
     836    } 
     837    return $res; 
     838} 
     839 
     840// translate bytes into kb, mb, gb or tb by CrappoMan 
    749841function parsebytesize($size,$digits=2,$dir=false) { 
    750842    $kb=1024; $mb=1024*$kb; $gb=1024*$mb; $tb=1024*$gb; 
  • trunk/includes/forum_functions_include.php

    r1274 r1291  
    400400        $result = dbquery("SELECT DISTINCT tag FROM ".$db_prefix."wiki_pages"); 
    401401        while ($data = dbarray($result)) { 
    402             $search[] = "/(\s)(".$data['tag'].")(\s)/is"; 
     402            $search[] = "/([[:space:]]|=|^)?(".$data['tag'].")([[:space:]]+?|\]|$)/i"; 
    403403            $replace[] = "\\1[wiki]\\2[/wiki]\\3"; 
    404404        } 
  • trunk/includes/template-plugins/function.imagelink.php

    r1254 r1291  
    6060        $alt = $params['alt']; 
    6161    } 
    62     if (!isset($params['style'])) { 
    63         $style = false; 
    64     } else { 
    65         $style = $params['style']; 
     62    $style = "vertical-align:text-top;"; 
     63    if (isset($params['style'])) { 
     64        $style .= $params['style']; 
    6665    } 
    6766    if (!isset($params['onclick'])) { 
Note: See TracChangeset for help on using the changeset viewer.