-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
111 lines (91 loc) · 2.06 KB
/
functions.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
session_start();
include_once 'config.php';
//SANITIZE USER INPUT
function test_input($text){
$text = trim($text);
$text = strip_tags($text);
$text = stripslashes($text);
return $text;
}
//TIME AGO FUNCTION
function time_Ago($time) {
$time = strtotime($time);
// Calculate difference between current
// time and given timestamp in seconds
$diff = time() - $time;
// Time difference in seconds
$sec = $diff;
// Convert time difference in minutes
$min = round($diff / 60 );
// Convert time difference in hours
$hrs = round($diff / 3600);
// Convert time difference in days
$days = round($diff / 86400 );
// Convert time difference in weeks
$weeks = round($diff / 604800);
// Convert time difference in months
$mnths = round($diff / 2600640 );
// Convert time difference in years
$yrs = round($diff / 31207680 );
// Check for seconds
if($sec <= 60) {
$date = "$sec sec ago";
}
// Check for minutes
else if($min <= 60) {
if($min==1) {
$date = "one min ago";
}
else {
$date = "$min min ago";
}
}
// Check for hours
else if($hrs <= 24) {
if($hrs == 1) {
$date = "an hour ago";
}
else {
$date ="$hrs hours ago";
}
}
// Check for days
else if($days <= 7) {
if($days == 1) {
$date = "Yesterday";
}
else {
$date = "$days days ago";
}
}
// Check for weeks
else if($weeks <= 4.3) {
if($weeks == 1) {
$date = "a week ago";
}
else {
$date = "$weeks weeks ago";
}
}
// Check for months
else if($mnths <= 12) {
if($mnths == 1) {
$date = "a month ago";
}
else {
$date = "$mnths months ago";
}
}
// Check for years
else {
if($yrs == 1) {
$date = "one year ago";
}
else {
$date = "$yrs years ago";
}
}
return $date;
}
?>