-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeed.php
More file actions
53 lines (48 loc) · 2.21 KB
/
Copy pathfeed.php
File metadata and controls
53 lines (48 loc) · 2.21 KB
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
<?php
$feed = new DOMDocument();
$feed->load($_GET['feed_url']);
$json = array();
$files = array();
$items = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');
foreach($items as $c => $item) {
$title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
$description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
$content = $item->getElementsByTagName('encoded')->item(0)->firstChild->nodeValue;
$creator = $item->getElementsByTagName('creator')->item(0)->firstChild->nodeValue;
$author = $item->getElementsByTagName('author')->item(0)->firstChild->nodeValue;
$category = $item->getElementsByTagName('category')->item(0)->firstChild->nodeValue;
$pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
$guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;
$comments = $item->getElementsByTagName('comments')->item(0)->firstChild->nodeValue;
if ($item->getElementsByTagName('enclosure')->item(0)) {
$img_url = $item->getElementsByTagName('enclosure')->item(0)->getAttribute('url');
$files[] = $img_url;
}
$json[$c]['title'] = $title;
$json[$c]['description'] = strip_tags($description);
$json[$c]['date'] = substr($pubDate, 5, -15);
$json[$c]['guid'] = $guid;
$json[$c]['contents'] = strip_tags($content);
if ($author) {
$json[$c]['author'] = $author;
} else {
$json[$c]['author'] = $creator;
}
$json[$c]['comments'] = $comments;
$json[$c]['category'] = $category;
$json[$c]['img_url'] = $img_url;
$json[$c]['img'] = 'assets/'.basename( $img_url);
}
$zip = new ZipArchive();
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);
foreach($files as $file){
$download_file = file_get_contents($file);
$zip->addFromString('assets/'.basename($file),$download_file);
}
$zip->addFromString('feed.json',utf8_encode(json_encode($json)));
$zip->close();
header('Content-disposition: attachment; filename=JSON_feed.zip');
header('Content-type: application/zip');
readfile($tmp_file);
?>