-
Notifications
You must be signed in to change notification settings - Fork 0
/
News.php
51 lines (42 loc) · 1.08 KB
/
News.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
<?php
/**
* InfoAppl Bulletin Board Bot
* ===================
* UWiClab, University of Urbino
* ===================
* News class.
*/
class News
{
public $guid;
public $date;
public $link;
public $title;
public $pubDate;
function toHTML() {
return sprintf("<b>%s</b>\n<a href=\"%s\">link</a>", $this->title, $this->link);
}
function isStillFresh(News $news = null){
$pd = is_null($news) ? $this->pubDate : $news->pubDate;
$today = new DateTime();
$diff = $today->diff($pd);
$hours = $diff->h;
$hours = $hours + ($diff->days*24);
return $hours < 24;
}
public static function extractGUID(News $n){
return $n->guid;
}
public static function toGUIDsArray($NewsArray){
return array_map(array("News", "extractGUID"), $NewsArray);
}
public static function filterOutOldNewsArray($news_array){
$news = array();
foreach ($news_array as $n) {
if($n->isStillFresh()){
$news[] = $n;
}
}
return $news;
}
}