add function getPeriodOfTime() and isAjax()

This commit is contained in:
Uwe Steinmann 2020-12-07 10:24:30 +01:00
parent c29de3a7ca
commit f2d5b160c5

View File

@ -46,6 +46,29 @@ function getLongReadableDate($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
*
@ -624,6 +647,13 @@ function getToken($length){ /* {{{ */
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
*