-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathresmushit.inc.php
57 lines (49 loc) · 1.31 KB
/
resmushit.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require('resmushit.settings.php');
require('classes/resmushit.class.php');
require('classes/resmushitUI.class.php');
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require('classes/resmushitWPCLI.class.php');
}
//require('resmushit.admin.php');
/**
*
* Calculates time ago
*
* @param string $datetime time input
* @param boolean $full number of lines to keep
* @param string $adaptative will preserve line memory
* @return string
* @author Glavić
* @link https://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago
*/
function time_elapsed_string($duration, $full = false) {
$datetime = "@" . (time() - $duration);
$now = new DateTime;
$then = new DateTime( $datetime );
$diff = (array) $now->diff( $then );
$diff['w'] = floor( $diff['d'] / 7 );
$diff['d'] -= $diff['w'] * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach( $string as $k => & $v )
{
if ( $diff[$k] )
{
$v = $diff[$k] . ' ' . $v .( $diff[$k] > 1 ? 's' : '' );
}
else
{
unset( $string[$k] );
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) : __('just now', 'resmushit-image-optimizer');
}