-
Notifications
You must be signed in to change notification settings - Fork 0
/
VINewsManager.php
66 lines (51 loc) · 1.51 KB
/
VINewsManager.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
<?php
class VINewsManager {
static protected $items = array();
static public function addItem($date_str, $title) {
$item = new VINewsItem($date_str, $title);
self::$items[$item->getID()] = $item;
return $item;
}
static public function getItem($id) {
if (!isset(self::$items[$id])) {
return null;
}
return self::$items[$id];
}
static public function allItems() {
return self::$items;
}
static public function getNewsBox($count) {
$html = '<ul class="news-box">';
$i = 0;
foreach (self::allItems() as $item) {
$html .= '<li><a href="/news/'.$item->getID().'"><small>'.$item->getDateAsString().'</small> '.$item->title.'</a></li>';
$i++;
if ($i>=$count) {
break;
}
}
$html .= '</ul>';
return $html;
}
}
class VINewsItem {
protected $id;
public $title;
public $date;
public $content;
public function __construct($date_str, $title) {
$this->id = preg_replace("/[-]+/", "-", preg_replace("/[^a-z0-9-]/", "", strtolower( str_replace(" ", "-", $title) ) ) );;
$this->title = $title;
date_default_timezone_set('Europe/Berlin'); // TODO: generalize
$this->date = strtotime($date_str);
}
public function getID() {
return $this->id;
}
public function getDateAsString($fmt="d.m.y") {
date_default_timezone_set('UTC');
return date($fmt, $this->date);
}
}
?>