-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosts.php
More file actions
80 lines (74 loc) · 2.35 KB
/
Posts.php
File metadata and controls
80 lines (74 loc) · 2.35 KB
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
<?php
require "./model/Articles.php";
class Posts{
function GetPosts($postId){
$postObj = new Articles();
if(!empty($postId)){
return $postObj->Article($postId);
}
else{
return $postObj->Article("");
}
}
function JustNowTiming($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$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) . ' ago' : 'just now';
}
function ReadingTime($content) {
$word_count = str_word_count(strip_tags($content));
$contLen = strlen(strip_tags($content));//200
$minutes = floor($word_count / $contLen);
$seconds = floor($word_count % $contLen / ($contLen / 60));
$str_minutes = ($minutes == 1) ? "min" : "mins";
$str_seconds = ($seconds == 1) ? "sec" : "secs";
if ($minutes == 0) {
return "{$seconds} {$str_seconds}";
}
else {
return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}";
}
}
function AlterNateName($name){
$returnName = $name;
$propName = explode(' ',$name);
if(sizeof($propName) > 1){
$firstLetter = substr($propName[0],0,1);
$secondLetter = substr($propName[1],0,1);
$returnName = strtoupper($firstLetter.$secondLetter);
}
else{
$returnName = $name;
}
return $returnName;
}
function NewPost($post = array()){
$postObj = new Articles();
return $postObj->AddPost($post);
}
function GetFeatured(){
$postObj = new Articles();
return $postObj->FeaturedArticle();
}
}
?>