...
|
...
|
@@ -0,0 +1,112 @@
|
|
1
|
+<?php
|
|
2
|
+include_once( 'news-constants.php' );
|
|
3
|
+
|
|
4
|
+$rss_content = file_get_contents(NEWS_RSS_STWORLD);
|
|
5
|
+$orgStrings = array( 'media:thumbnail');
|
|
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['title'] = $xml->channel->title;
|
|
14
|
+ $channel['link'] = $xml->channel->link;
|
|
15
|
+ $channel['description'] = $xml->channel->description;
|
|
16
|
+ $channel['pubDate'] = $xml->channel->pubDate;
|
|
17
|
+ $channel['timestamp'] = strtotime($xml->channel->pubDate);
|
|
18
|
+ echo '<h4>' . $channel['title'] . '</h4>';
|
|
19
|
+ $cpt=0;
|
|
20
|
+ foreach ($xml->channel->item as $item) {
|
|
21
|
+ $article = array();
|
|
22
|
+ $article['title'] = $item->title;
|
|
23
|
+ $article['link'] = $item->link;
|
|
24
|
+ $article['pubDate'] = $item->pubDate;
|
|
25
|
+ $article['timestamp'] = strtotime($item->pubDate);
|
|
26
|
+ $article['description'] = $item->description;
|
|
27
|
+ //$article['image'] = $item->mediacontent['url'];
|
|
28
|
+ $articles[$cpt] = $article;
|
|
29
|
+ echo '<div onclick="onArticle('.$cpt.')" style="display:inline;">';
|
|
30
|
+// echo '<img id="img-list" src="'.$article['image'].'" style="display:block;"><br>';
|
|
31
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> ';
|
|
32
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-down fa-2x"></i></a></div> ';
|
|
33
|
+ echo $article['title'].' ';
|
|
34
|
+ 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>';
|
|
35
|
+ $cpt++;
|
|
36
|
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
|
|
37
|
+ break;
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+echo '</div><!-- ./col-4 -->'.PHP_EOL;
|
|
43
|
+echo '<div id="article-display" class="col-6">'.PHP_EOL;
|
|
44
|
+echo '<a name="article-top"></a><div id="article-current"></div>'.PHP_EOL;
|
|
45
|
+echo '</div><!-- ./col-6 -->'.PHP_EOL;
|
|
46
|
+
|
|
47
|
+$cpt=0;
|
|
48
|
+foreach ($articles as $article ) {
|
|
49
|
+ $cpt_prev=$cpt-1;
|
|
50
|
+ $cpt_next=$cpt+1;
|
|
51
|
+ echo '<!-- ==================== article '.$cpt.'============== -->';
|
|
52
|
+ echo "<div class=\"article\" id=\"article-$cpt\" style=\"display: none;\">\n";
|
|
53
|
+ echo "<hr>";
|
|
54
|
+ echo "<a name=\"article-$cpt\">";
|
|
55
|
+ $article_content = file_get_contents($article['link']);
|
|
56
|
+ $doc = new DOMDocument();
|
|
57
|
+ $doc->preserveWhiteSpace = false;
|
|
58
|
+ $doc->formatOutput = true;
|
|
59
|
+ $libxml_previous_state = libxml_use_internal_errors(true);
|
|
60
|
+ //Hack
|
|
61
|
+ $orgStrings = array('itemprop="articleBody"');
|
|
62
|
+ $newStrings = array('id="articleBody"');
|
|
63
|
+ $article_content = str_replace($orgStrings, $newStrings, $article_content);
|
|
64
|
+ $doc->loadHTML($article_content);
|
|
65
|
+ libxml_clear_errors();
|
|
66
|
+ libxml_use_internal_errors($libxml_previous_state);
|
|
67
|
+ $articleBody = $doc->getElementByID('articleBody');
|
|
68
|
+ if(NULL!= $articleBody) {
|
|
69
|
+ $article_only = DOMinnerHTML($articleBody);
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ $SEARCH_SUB='<div class="c-save-for-later--default is-article-bottom-position"';
|
|
73
|
+ $pos_start=strpos($article_only, $SEARCH_SUB);
|
|
74
|
+ if($pos_start) {
|
|
75
|
+ $article_only = substr($article_only,0,$pos_start);
|
|
76
|
+ }
|
|
77
|
+ //Extract image
|
|
78
|
+ //$re = '/<link rel="image_src" href="(.+?)"\/>/';
|
|
79
|
+ $re = '/<div class="media-entity" rel="" resource="(.+?)">/';
|
|
80
|
+ $imageurl="";
|
|
81
|
+ preg_match($re, $article_content, $matches);
|
|
82
|
+ if(isset($matches[1]))
|
|
83
|
+ $imageurl = $matches[1];
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ //Clean some sections
|
|
87
|
+ //$article_only = re_remove($article_only, '//');
|
|
88
|
+ $article_only = re_remove($article_only, '/googletag\.display\("(.+?)"\);/');
|
|
89
|
+
|
|
90
|
+ //Finally remove empty lines
|
|
91
|
+ $article_only = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only);
|
|
92
|
+
|
|
93
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
|
|
94
|
+ 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;
|
|
95
|
+ echo '<button id="html-btn" onclick="printHTML()" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL;
|
|
96
|
+ echo '<button id="pdf-btn" onclick="printPDF()" style="display:inline;"><img src="img/pdf.png" width="24px" height="24px"></button>'.PHP_EOL;
|
|
97
|
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
|
|
98
|
+ echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div>'.PHP_EOL;
|
|
99
|
+ echo '<div class="extract-content" id="'.$cpt.'"><h1>'.$article['title'].'</h1><img src="'.$imageurl.'">'.$article_only.'</div>'.PHP_EOL;
|
|
100
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
|
|
101
|
+ 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;
|
|
102
|
+ 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;
|
|
103
|
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
|
|
104
|
+ 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;
|
|
105
|
+ $cpt++;
|
|
106
|
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
|
|
107
|
+ break;
|
|
108
|
+ }
|
|
109
|
+}
|
|
110
|
+?>
|
|
111
|
+
|
|
112
|
+
|