... | ... |
@@ -0,0 +1,98 @@ |
1 |
+<?php |
|
2 |
+include_once( 'news-constants.php' ); |
|
3 |
+ |
|
4 |
+$rss_content = file_get_contents(NEWS_RSS_FT); |
|
5 |
+$orgStrings = array( 'media:content'); |
|
6 |
+$newStrings = array( 'mediacontent'); |
|
7 |
+$rss_content = str_replace($orgStrings, $newStrings, $rss_content); |
|
8 |
+$xml = simplexml_load_string($rss_content); |
|
9 |
+if ($xml === false) { |
|
10 |
+ echo 'Failed to read RSS'; |
|
11 |
+} else { |
|
12 |
+ $channel = array(); |
|
13 |
+ $channel['name'] = "guardian"; |
|
14 |
+ $channel['title'] = $xml->channel->title; |
|
15 |
+ $channel['link'] = $xml->channel->link; |
|
16 |
+ $channel['description'] = $xml->channel->description; |
|
17 |
+ $channel['pubDate'] = $xml->channel->pubDate; |
|
18 |
+ $channel['timestamp'] = strtotime($xml->channel->pubDate); |
|
19 |
+ echo '<h4>' . $channel['title'].PHP_EOL; |
|
20 |
+ echo '<button id="html-btn" onclick="printHTMLAll(\''.$channel['name'].'.html\')" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL; |
|
21 |
+ echo '<button id="pdf-btn" onclick="printPDFAll(\''.$channel['name'].'.pdf\')" style="display:inline;"><img src="img/pdf.png" width="24px" height="24px"></button>'.PHP_EOL; |
|
22 |
+ echo '</h4>'.PHP_EOL; |
|
23 |
+ $cpt=0; |
|
24 |
+ foreach ($xml->channel->item as $item) { |
|
25 |
+ $article = array(); |
|
26 |
+ $article['title'] = $item->title; |
|
27 |
+ $article['link'] = $item->link; |
|
28 |
+ $article['pubDate'] = $item->pubDate; |
|
29 |
+ $article['timestamp'] = strtotime($item->pubDate); |
|
30 |
+ $article['description'] = $item->description; |
|
31 |
+ $article['image'] = $item->mediacontent['url']; |
|
32 |
+ $articles[$cpt] = $article; |
|
33 |
+ |
|
34 |
+ echo '<div onclick="onArticle('.$cpt.')" style="display:inline;">'.PHP_EOL; |
|
35 |
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL; |
|
36 |
+ echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-down fa-2x"></i></a></div> '.PHP_EOL; |
|
37 |
+ echo $article['title'].' '.PHP_EOL; |
|
38 |
+ echo '<div id="nav-source" style="display:inline;"><a href="'.$article['link'].'" target="new-'.$cpt.'"><i class="fa fa-link fa-2x"></i></a><br></div></div>'.PHP_EOL; |
|
39 |
+ $cpt++; |
|
40 |
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) { |
|
41 |
+ break; |
|
42 |
+ } |
|
43 |
+ } |
|
44 |
+} |
|
45 |
+ |
|
46 |
+echo '</div><!-- ./col-4 -->'.PHP_EOL; |
|
47 |
+echo '<div id="article-display" class="col-6">'.PHP_EOL; |
|
48 |
+echo '<a name="article-top"></a><div id="article-current"></div>'.PHP_EOL; |
|
49 |
+echo '</div><!-- ./col-6 -->'.PHP_EOL; |
|
50 |
+ |
|
51 |
+$cpt=0; |
|
52 |
+foreach ($articles as $article ) { |
|
53 |
+ $cpt_prev=$cpt-1; |
|
54 |
+ $cpt_next=$cpt+1; |
|
55 |
+ echo '<!-- ==================== article '.$cpt.'============== -->'; |
|
56 |
+ echo "<div class=\"article\" id=\"article-$cpt\" style=\"display: none;\">\n"; |
|
57 |
+ echo "<hr>"; |
|
58 |
+ echo "<a name=\"article-$cpt\">"; |
|
59 |
+ //Force AMP |
|
60 |
+ $article['link'] = str_replace("www","amp", $article['link']); |
|
61 |
+ WARNING($article['link']); |
|
62 |
+ $article_content = file_get_contents($article['link']); |
|
63 |
+ $doc = new DOMDocument(); |
|
64 |
+ $doc->preserveWhiteSpace = false; |
|
65 |
+ $doc->formatOutput = true; |
|
66 |
+ $libxml_previous_state = libxml_use_internal_errors(true); |
|
67 |
+ $doc->loadHTML($article_content); |
|
68 |
+ libxml_clear_errors(); |
|
69 |
+ libxml_use_internal_errors($libxml_previous_state); |
|
70 |
+ $articles = $doc->getElementsByTagName('article'); |
|
71 |
+ $article_only=""; |
|
72 |
+ foreach ( $articles as $node) { |
|
73 |
+ $article_only = DOMinnerHTML($node); |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ $re = '/<amp-img/'; |
|
77 |
+ $article_only = preg_replace($re, '<img', $article_only); |
|
78 |
+ $article_only = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only); |
|
79 |
+ |
|
80 |
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL; |
|
81 |
+ echo '<div id="nav-source" style="display:inline;"><a href="'.$article['link'].'" target="new-'.$cpt.'"><i class="fa fa-link fa-2x"></i></a></div> '.PHP_EOL; |
|
82 |
+ echo '<button id="html-btn" onclick="printHTML()" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL; |
|
83 |
+ echo '<button id="pdf-btn" onclick="printPDF()" style="display:inline;"><img src="img/pdf.png" width="24px" height="24px"></button>'.PHP_EOL; |
|
84 |
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL; |
|
85 |
+ echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div>'.PHP_EOL; |
|
86 |
+ //echo '<div class="extract-content" id="'.$cpt.'">'."<h1>".$article['title']."</h1>".$article_only.'</div>'.PHP_EOL; |
|
87 |
+ echo '<div class="extract-content" id="'.$cpt.'">'.$article_only.'</div>'.PHP_EOL; |
|
88 |
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL; |
|
89 |
+ echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-up fa-2x"></i></a></div> '.PHP_EOL; |
|
90 |
+ echo '<div id="nav-source" style="display:inline;"><a href="'.$article['link'].'" target="new-'.$cpt.'"><i class="fa fa-link fa-2x"></i></a></div> '.PHP_EOL; |
|
91 |
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL; |
|
92 |
+ echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div></div>'.PHP_EOL; |
|
93 |
+ $cpt++; |
|
94 |
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) { |
|
95 |
+ break; |
|
96 |
+ } |
|
97 |
+} |
|
98 |
+?> |
... | ... |
@@ -12,6 +12,7 @@ define('NEWS_RSS_STASIA', 'https://www.straitstimes.com/news/asia/rss.xml'); |
12 | 12 |
define('NEWS_RSS_STWORLD', 'https://www.straitstimes.com/news/world/rss.xml'); |
13 | 13 |
define('NEWS_RSS_STAR', 'https://www.thestar.com/content/thestar/feed.RSSManagerServlet.articles.news.world.rss'); |
14 | 14 |
define('NEWS_RSS_NYKR_MAG', 'https://www.newyorker.com/feed/magazine/rss'); |
15 |
+define('NEWS_RSS_FT', 'https://www.ft.com/news-feed?format=rss'); |
|
15 | 16 |
|
16 | 17 |
$array_title=array( |
17 | 18 |
"nyt" => "New York Times", |
... | ... |
@@ -25,7 +26,8 @@ $array_title=array( |
25 | 26 |
"nykrmag" => "New Yorker", |
26 | 27 |
"stsg" => "ST Singapore", |
27 | 28 |
"stasia" => "ST Asia", |
28 |
- "stworld" => "ST World" |
|
29 |
+ "stworld" => "ST World", |
|
30 |
+ "ft" => "Financial Times" |
|
29 | 31 |
); |
30 | 32 |
$array_url=array( |
31 | 33 |
"nyt" => NEWS_RSS_NYT, |
... | ... |
@@ -39,7 +41,8 @@ $array_url=array( |
39 | 41 |
"nykrmag" => NEWS_RSS_NYKR_MAG, |
40 | 42 |
"stsg" => NEWS_RSS_STSG, |
41 | 43 |
"stasia" => NEWS_RSS_STASIA, |
42 |
- "stworld" => NEWS_RSS_STWORLD |
|
44 |
+ "stworld" => NEWS_RSS_STWORLD, |
|
45 |
+ "ft" => NEWS_RSS_FT |
|
43 | 46 |
); |
44 | 47 |
|
45 | 48 |
function DEBUG($Message) { |