2014-09-24 01:22:41 +02:00
|
|
|
<?php
|
|
|
|
define( 'MINUTE_IN_SECONDS', 60 );
|
|
|
|
define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS );
|
|
|
|
define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );
|
|
|
|
define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
|
|
|
|
define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
|
|
|
|
|
|
|
|
function _n($x, $y, $z) {
|
|
|
|
if ($z > 1) {
|
|
|
|
return $y;
|
|
|
|
} else {
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function human_time_diff( $from, $to = '' ) {
|
|
|
|
if ( empty( $to ) )
|
|
|
|
$to = time();
|
|
|
|
|
|
|
|
$diff = (int) abs( $to - $from );
|
|
|
|
|
|
|
|
if ( $diff < HOUR_IN_SECONDS ) {
|
|
|
|
$mins = round( $diff / MINUTE_IN_SECONDS );
|
|
|
|
if ( $mins <= 1 )
|
|
|
|
$mins = 1;
|
|
|
|
/* translators: min=minute */
|
|
|
|
$since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
|
|
|
|
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
|
|
|
|
$hours = round( $diff / HOUR_IN_SECONDS );
|
|
|
|
if ( $hours <= 1 )
|
|
|
|
$hours = 1;
|
|
|
|
$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
|
|
|
|
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
|
|
|
|
$days = round( $diff / DAY_IN_SECONDS );
|
|
|
|
if ( $days <= 1 )
|
|
|
|
$days = 1;
|
|
|
|
$since = sprintf( _n( '%s day', '%s days', $days ), $days );
|
|
|
|
} elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
|
|
|
|
$weeks = round( $diff / WEEK_IN_SECONDS );
|
|
|
|
if ( $weeks <= 1 )
|
|
|
|
$weeks = 1;
|
|
|
|
$since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
|
|
|
|
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
|
|
|
|
$months = round( $diff / ( 30 * DAY_IN_SECONDS ) );
|
|
|
|
if ( $months <= 1 )
|
|
|
|
$months = 1;
|
|
|
|
$since = sprintf( _n( '%s month', '%s months', $months ), $months );
|
|
|
|
} elseif ( $diff >= YEAR_IN_SECONDS ) {
|
|
|
|
$years = round( $diff / YEAR_IN_SECONDS );
|
|
|
|
if ( $years <= 1 )
|
|
|
|
$years = 1;
|
|
|
|
$since = sprintf( _n( '%s year', '%s years', $years ), $years );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $since;
|
|
|
|
}
|
2015-04-06 22:37:47 +02:00
|
|
|
|
|
|
|
function is_billion_laughs($arr1, $arr2) {
|
|
|
|
$arr = array();
|
|
|
|
foreach ($arr1 as $k => $v) {
|
|
|
|
$arr[$v] = $arr2[$k];
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i <= sizeof($arr); $i++) {
|
|
|
|
$cur = array_slice($arr, $i, 1);
|
|
|
|
$pst = array_slice($arr, 0, $i);
|
|
|
|
if (!$cur) continue;
|
|
|
|
$kk = array_keys($cur)[0];
|
|
|
|
$vv = array_values($cur)[0];
|
|
|
|
foreach ($pst as $k => $v) {
|
|
|
|
if (str_replace($kk, $vv, $v) != $v)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|