-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloworld.php
125 lines (114 loc) · 5.9 KB
/
helloworld.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
function getContent() {
//Thanks to https://davidwalsh.name/php-cache-function for cache idea
$file = "./feed-cache.txt";
$current_time = time();
$expire_time = 5 * 60;
$file_time = filemtime($file);
if(file_exists($file) && ($current_time - $expire_time < $file_time)) {
return file_get_contents($file);
}
else {
$content = getFreshContent();
file_put_contents($file, $content);
return $content;
}
}
function getFreshContent() {
$html = '<html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Lite</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body><div class="container">';
$newsSource = array(
array(
"title" => "Jeffrey Sachs",
"url" => "https://www.twitrss.me/twitter_user_to_rss/?user=jeffdsachs"
),
array(
"title" => "Nature",
"url" => "https://www.twitrss.me/twitter_user_to_rss/?user=NatureNews"
),
array(
"title" => "TechCrunch",
"url" => "http://feeds.feedburner.com/Techcrunch/europe"
),
array(
"title" => "Handelsblatt",
"url" => "http://www.handelsblatt.com/contentexport/feed/top-themen"
),
array(
"title" => "Google US",
"url" => "https://news.google.com/news/rss/?gl=US&ned=us&hl=en"
),
array(
"title" => "Google IN",
"url" => "https://news.google.com/news/rss/?ned=in&gl=IN&hl=en-IN"
),
array(
"title" => "Google GB",
"url" => "https://news.google.com/news/rss/?ned=uk&gl=GB&hl=en-GB"
),
array(
"title" => "The Hindu",
"url" => "http://www.thehindu.com/news/national/?service=rss"
),
array(
"title" => "Hacker News",
"url" => "https://news.ycombinator.com/rss"
),
array(
"title" => "The Local",
"url" => "https://www.thelocal.de/feeds/rss.php"
),
array(
"title" => "Spiegel",
"url" => "http://www.spiegel.de/schlagzeilen/tops/index.rss"
),
array(
"title" => "Reuters",
"url" => "http://feeds.reuters.com/reuters/topNews"
),
array(
"title" => "FAZ",
"url" => "http://www.faz.net/rss/aktuell/"
),
array(
"title" => "Hessenschau",
"url" => "http://www.hessenschau.de/index.rss"
),
array(
"title" => "Gnome",
"url" => "http://planet.gnome.org/rss20.xml"
),
array(
"title" => "Hessenschau",
"url" => "http://www.hessenschau.de/index.rss"
),
);
function getFeed($url){
$rss = simplexml_load_file($url);
$count = 0;
$html .= '<ul>';
foreach($rss->channel->item as$item) {
$count++;
if($count > 9){
break;
}
// $html .= '<br>'.htmlspecialchars($item->description).'<li><a href="'.htmlspecialchars($item->link).'">'.htmlspecialchars($item->title).'</a></li><br>';
$html .= '<li><a href="'.htmlspecialchars($item->link).'">'.htmlspecialchars($item->title).'</a></li><br>';
}
$html .= '</ul>';
return $html;
}
foreach($newsSource as $source) {
$html .= '<h2>'.$source["title"].'</h2>';
$html .= getFeed($source["url"]);
}
return $html;
}
print getContent();