...
|
...
|
@@ -0,0 +1,119 @@
|
|
1
|
+<?php
|
|
2
|
+include_once( 'news-constants.php' );
|
|
3
|
+
|
|
4
|
+$rss_content = file_get_contents(NEWS_RSS_STAR);
|
|
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['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'];
|
|
19
|
+ echo '<button id="html-btn" onclick="printHTMLAll(\''.$channel['title'].'\')" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL;
|
|
20
|
+ echo '</h4>';
|
|
21
|
+ $cpt=0;
|
|
22
|
+ foreach ($xml->channel->item as $item) {
|
|
23
|
+ $article = array();
|
|
24
|
+ $article['title'] = $item->title;
|
|
25
|
+ $article['link'] = $item->link;
|
|
26
|
+ $SEARCHREF="?ref=rss";
|
|
27
|
+ //Remove reference from links
|
|
28
|
+ $posref=strpos($article['link'], $SEARCHREF);
|
|
29
|
+ if( $posref ) {
|
|
30
|
+ $article['link'] = substr($article['link'],0,$posref);
|
|
31
|
+ }
|
|
32
|
+ $article['pubDate'] = $item->pubDate;
|
|
33
|
+ $article['timestamp'] = strtotime($item->pubDate);
|
|
34
|
+ $article['description'] = $item->description;
|
|
35
|
+ $article['image'] = $item->mediacontent['url'];
|
|
36
|
+ $articles[$cpt] = $article;
|
|
37
|
+
|
|
38
|
+ echo '<div onclick="onArticle('.$cpt.')" style="display:inline;">'.PHP_EOL;
|
|
39
|
+ echo '<div class="img-menu"><img src="'.$article['image'].'" style="display:inline;" width="100%"></div><br>'.PHP_EOL;
|
|
40
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
|
|
41
|
+ 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;
|
|
42
|
+ echo $article['title'].' ';
|
|
43
|
+ 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;
|
|
44
|
+ $cpt++;
|
|
45
|
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
|
|
46
|
+ break;
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+}
|
|
50
|
+
|
|
51
|
+echo '</div><!-- ./col-4 -->'.PHP_EOL;
|
|
52
|
+echo '<div id="article-display" class="col-6">'.PHP_EOL;
|
|
53
|
+echo '<a name="article-top"></a><div id="article-current"></div>'.PHP_EOL;
|
|
54
|
+echo '</div><!-- ./col-6 -->'.PHP_EOL;
|
|
55
|
+
|
|
56
|
+$cpt=0;
|
|
57
|
+foreach ($articles as $article ) {
|
|
58
|
+ $cpt_prev=$cpt-1;
|
|
59
|
+ $cpt_next=$cpt+1;
|
|
60
|
+ echo '<!-- ==================== article '.$cpt.'============== -->';
|
|
61
|
+ echo "<div class=\"article\" id=\"article-$cpt\" style=\"display: none;\">\n";
|
|
62
|
+ echo "<hr>";
|
|
63
|
+ echo "<a name=\"article-$cpt\">";
|
|
64
|
+ $article_content = file_get_contents($article['link']);
|
|
65
|
+ $doc = new DOMDocument();
|
|
66
|
+ $doc->preserveWhiteSpace = false;
|
|
67
|
+ $doc->formatOutput = true;
|
|
68
|
+ $libxml_previous_state = libxml_use_internal_errors(true);
|
|
69
|
+ $doc->loadHTML($article_content);
|
|
70
|
+ libxml_clear_errors();
|
|
71
|
+ libxml_use_internal_errors($libxml_previous_state);
|
|
72
|
+
|
|
73
|
+ //Article is in <div class="article-body-items"
|
|
74
|
+ $articles = $doc->getElementsByTagName('div');
|
|
75
|
+ $article_only = "";
|
|
76
|
+ WARNING($cpt);
|
|
77
|
+ foreach ( $articles as $node) {
|
|
78
|
+ $classname = $node->getAttribute('class');
|
|
79
|
+ if($classname == 'article-body-items' ) {
|
|
80
|
+ $article_only = DOMinnerHTML($node);
|
|
81
|
+ break;
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+ if( 0 == strlen($article_only)) {
|
|
85
|
+ $article_only = "Extraction failed";
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ $article_only = re_remove($article_only, '/<div class="side-box__button"><span><span><a href="\/emails\.html">SIGN UP<\/a><\/span><\/span><\/div>/');
|
|
89
|
+ $article_only = re_remove($article_only, '/<span class="subline-icon-color-headlines">NEW NEWSLETTER<\/span><span>HEADLINES<\/span>/');
|
|
90
|
+ $article_only = re_remove($article_only, '/<li class="report-error"><a><i class="staricon staricon-error-reporting "><\/i>Report an error<\/a><\/li>/');
|
|
91
|
+ $article_only = re_remove($article_only, '/<li class="about-the"><span><span><a href="\/about\/aboutus\.html"><i class="staricon staricon-trust-icon "><\/i>About <em>The Star<\/em><\/a><\/span><\/span><\/li>/');
|
|
92
|
+ $article_only = re_remove($article_only, '/<div class="banner-inner-content__left side-box__title title-color-headlines"><div class="about-text">TOP STORIES, DELIVERED TO YOUR INBOX.<\/div><\/div>/');
|
|
93
|
+ $article_only = re_remove($article_only, '/<li class="journalistic-standards"><span><span><a href="\/about\/statementofprinciples.html"><i class="staricon staricon-journalistic-standards "><\/i>Journalistic Standards<\/a><\/span><\/span><\/li>/');
|
|
94
|
+ $article_only = re_remove($article_only, '/<div class="article-continued"><div class="article-continued__heading">Article Continued Below<\/div><\/div>/');
|
|
95
|
+ $article_only = re_remove($article_only, '/<div class="alpha__big-box__body"><div class="big-box"><\/div><\/div>/');
|
|
96
|
+ //$article_only = re_remove($article_only, '//');
|
|
97
|
+ //$article_only = re_remove($article_only, '//');
|
|
98
|
+ $article_only = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only);
|
|
99
|
+
|
|
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-source" style="display:inline;"><a href="'.$article['link'].'" target="new-'.$cpt.'"><i class="fa fa-link fa-2x"></i></a></div> '.PHP_EOL;
|
|
102
|
+ echo '<button id="html-btn" onclick="printHTML()" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL;
|
|
103
|
+ echo '<button id="pdf-btn" onclick="printPDF()" style="display:inline;"><img src="img/pdf.png" width="24px" height="24px"></button>'.PHP_EOL;
|
|
104
|
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
|
|
105
|
+ echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div>'.PHP_EOL;
|
|
106
|
+ echo '<div class="extract-content" id="'.$cpt.'">'.'<h1>'.$article['title'].'</h1>'.$article_only.'</div>';
|
|
107
|
+ echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
|
|
108
|
+ 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;
|
|
109
|
+ 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;
|
|
110
|
+ echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
|
|
111
|
+ 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;
|
|
112
|
+ $cpt++;
|
|
113
|
+ if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
|
|
114
|
+ break;
|
|
115
|
+ }
|
|
116
|
+}
|
|
117
|
+?>
|
|
118
|
+
|
|
119
|
+
|