mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-09-09 19:38:57 +00:00
add function getPeriodOfTime() and isAjax()
This commit is contained in:
parent
c29de3a7ca
commit
f2d5b160c5
|
@ -46,6 +46,29 @@ function getLongReadableDate($timestamp) { /* {{{ */
|
||||||
return date("Y-m-d H:i:s", $timestamp);
|
return date("Y-m-d H:i:s", $timestamp);
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
function getPeriodOfTime($timestamp) { /* {{{ */
|
||||||
|
if(!is_numeric($timestamp))
|
||||||
|
$timestamp = strtotime($timestamp);
|
||||||
|
|
||||||
|
$time = time() - $timestamp; // to get the time since that moment
|
||||||
|
$time = ($time<1)? 1 : $time;
|
||||||
|
$tokens = array (
|
||||||
|
31536000 => getMLText('abbr_year'),
|
||||||
|
2592000 => getMLText('abbr_month'),
|
||||||
|
604800 => getMLText('abbr_week'),
|
||||||
|
86400 => getMLText('abbr_day'),
|
||||||
|
3600 => getMLText('abbr_hour'),
|
||||||
|
60 => getMLText('abbr_minute'),
|
||||||
|
1 => getMLText('abbr_second')
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($tokens as $unit => $text) {
|
||||||
|
if ($time < $unit) continue;
|
||||||
|
$numberOfUnits = floor($time / $unit);
|
||||||
|
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
|
||||||
|
}
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converts a date/time string into a timestamp
|
* Converts a date/time string into a timestamp
|
||||||
*
|
*
|
||||||
|
@ -624,6 +647,13 @@ function getToken($length){ /* {{{ */
|
||||||
return $token;
|
return $token;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
function isAjax() { /* {{{ */
|
||||||
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash a password
|
* Hash a password
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user