From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- utils/news.php | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 utils/news.php (limited to 'utils/news.php') diff --git a/utils/news.php b/utils/news.php new file mode 100644 index 0000000..809e8dc --- /dev/null +++ b/utils/news.php @@ -0,0 +1,103 @@ +\n"; + echo "
" . + htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; + echo "
" . date("D M jS Y G:i", $this->time) . "
\n"; + echo "
" . + htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; + echo "\n"; + } + + public function NewsEntry($title, $time, $category, $description) + { + $this->title = $title; + $this->time = $time; + $this->category = $category; + $this->description = $description; + } +} + +class News { + + private $file; + private $news = array(); + + public function show($number, $category) + { + // If number is -1 show all shows. + if($number == -1) $number = 100000; + + foreach($this->news as $newsentry) { + if($newsentry->category == $category || $category == "all") { + $newsentry->show(); + $number--; + } + if(!$number) return; + } + } + + public function add($newsentry) { + $key = $newsentry->time; + $this->news[$key] = $newsentry; + } + + public function write() + { + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->news as $newsentry) { + fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " time=\"" . $newsentry->time . "\"\n"); + fwrite($fp, " category=\"" . $newsentry->category . "\"\n"); + fwrite($fp, " description=\"" . + htmlspecialchars($newsentry->description, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + private function read() + { + + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $params = $dom->getElementsByTagName('newsentry'); + + foreach ($params as $param) { + $newsentry = new NewsEntry($param->getAttribute('title'), + $param->getAttribute('time'), + $param->getAttribute('category'), + $param->getAttribute('description')); + $this->add($newsentry); + } + + // Key sort + krsort($this->news); + } + + public function News($file) + { + $this->file = $file; + $this->read(); + } + +} + +?> -- cgit v1.2.3