php const RSS_NAME rss xml const RSS_TITLE Последние новости const RSS

 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
<?php
const RSS_NAME = 'rss.xml';
const RSS_TITLE = 'Последние новости';
const RSS_LINK = 'http://mysite.local/news/news.php';
public function createRss(){
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$rss = $dom->createElement("rss");
$dom->appendChild($rss);
$version = $dom->createAttribute("version");
$version->value = '2.0';
$rss->appendChild($version);
$channel = $dom->createElement("channel");
$rss->appendChild($channel);
$title = $dom->createElement("title", self::RSS_TITLE);
$link = $dom->createElement("link", self::RSS_LINK);
$channel->appendChild($title);
$channel->appendChild($link);
$data = $this->getNews();
foreach ($date as $d) {
$item = $dom->createElement("item");
$title = $dom->createElement("title", $d['title']);
$link = $dom->createElement("link", $d['source']);
$description = $dom->createElement("description", $d['description']);
$pubDate = $dom->createElement("pubDate", date("d-m-Y",$d['datetime']);
$category = $dom->createElement("category", $d['category']);
$item->appendChild($title);
$item->appendChild($link);
$item->appendChild($description);
$item->appendChild($pubDate);
$item->appendChild($category);
$channel->appendChild($item);
}
$dom->save(self::RSS_NAME);
}
?>