-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
141 lines (122 loc) · 3.74 KB
/
post.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @author Seth G. R. Herendeen
* @license MIT
*/
class post {
private $postNo;
private $author = '';
private $textContent;
private $postDate;
private $fileName;
private $ipAddress;
private $altText;
/**
*
* @param int $postNo
* @param string $textContent
* @param string $ipAddress
* @param string $fileName
* @param string $author
* @param $postDate
*/
public function __construct(int $postNo = -1, string $textContent, string $ipAddress,
string $fileName = '', string $author = 'Anonymous', $postDate, string $altText = '') {
$this->postNo = $postNo;
$this->textContent = $textContent;
$this->author = $author;
$this->fileName = $fileName;
$this->postDate = $postDate;
$this->ipAddress = $ipAddress;
$this->altText = $altText;
}
/**
* @param string $fileName the name of the file
*/
public function setFileName(string $fileName) {
$this->fileName = $fileName;
}
public function getPostNo() : int {
return $this->postNo;
}
/**
* @return mixed
*/
public function getPostDate() {
return $this->postDate;
}
/**
* @return string the file name. e.g: "62831.jpg"
*/
public function getFileName() : string {
return $this->fileName . '';
}
/**
* @return $ipAddress of the poster
*/
public function getIpAddress() {
return $this->ipAddress;
}
public function getTextContent() : string {
return $this->textContent;
}
public function getAuthor() : string {
return $this->author;
}
public function getAltText() : string {
return $this->altText;
}
public function setAltText(string $altText): void {
$this->altText = $altText;
}
/**
*
* @param string $textContent
*/
public function setTextContent(string $textContent) {
$this->textContent = $textContent;
}
public function getPostDisplay() : string {
if (empty($this->fileName)) {
return "
<article class='post'>
<p>
<label>$this->author</label>
PostNo: $this->postNo - $this->postDate
</p>
<hr />
<p>$this->textContent</p>
</article>
";
} else if (post::endsWith('.webm', $this->fileName)) {
return "
<article class='post'>
<p>
<label>$this->author</label>
PostNo: $this->postNo - $this->postDate
</p>
<hr />
<video title=$alt class='thumbnail' controls>
<source src='$this->fileName' type='video/webm'>
</video>
<p>$this->textContent</p>
</article>
";
} else {
return "
<article class='post'>
<p>
<label>$this->author</label>
PostNo: $this->postNo - $this->postDate
</p>
<hr />
<img src='$this->fileName' class='thumbnail' alt='$this->altText' loading='lazy' />
<p>$this->textContent</p>
</article>
";
}
}
public static function endsWith($stringToFind, $str) : bool {
return preg_match('/' . preg_quote($stringToFind, '/') . '$/', $str);
}
} ?>