1 contributor
<?php
include_once( 'news-constants.php' );
$rss_content = http_get_contents(NEWS_RSS_VICEFR);
$rss_content = str_replace("<content:encoded>","<contentEncoded>",$rss_content);
$rss_content = str_replace("</content:encoded>","</contentEncoded>",$rss_content);
$articles = array();
$xml = simplexml_load_string($rss_content);
if ($xml === false) {
echo 'Failed to read RSS';
} else {
$channel = array();
$channel['name'] = "vicefr.html";
$channel['title'] = $xml->channel->title;
$channel['link'] = $xml->channel->link;
$channel['description'] = $xml->channel->description;
$channel['pubDate'] = $xml->channel->pubDate;
$channel['timestamp'] = strtotime($xml->channel->pubDate);
echo '<h4>' . $channel['title'].'<button id="html-btn" onclick="printHTMLAll(\''.$channel['name'].'\')" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button></h4>'.PHP_EOL;
echo '<button id="epub-btn" onclick="printEPUBAll(\''.$channel['name'].'.epub\')" style="display:inline;"><img src="img/epub.png" width="24px" height="24px"></button>'.PHP_EOL;
$cpt=0;
foreach ($xml->channel->item as $item) {
$article = array();
$article['title'] = $item->title;
$article['link'] = $item->link;
$article['pubDate'] = $item->pubDate;
$article['timestamp'] = strtotime($item->pubDate);
$article['description'] = $item->description;
$article['content'] = $item->contentEncoded;
$article['image'] = $item->enclosure['url'];
$articles[$cpt]=$article;
echo '<div onclick="onArticle('.$cpt.')" style="display:inline;">'.PHP_EOL;
echo '<div class="img-menu"><img src="'.$article['image'].'" style="display:inline;" width="100%"></div><br>'.PHP_EOL;
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-down fa-2x"></i></a></div> ';
echo $article['title'].' '.PHP_EOL;
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;
$cpt++;
if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
break;
}
}
}
echo '</div><!-- ./col-4 -->';
echo '<div id="article-display" class="col-6">'.PHP_EOL;
echo '<a name="article-top"></a><div id="article-current"></div>';
echo '</div><!-- ./col-6 -->'.PHP_EOL;
$cpt=0;
foreach ($articles as $article ) {
$cpt_prev=$cpt-1;
$cpt_next=$cpt+1;
echo PHP_EOL.PHP_EOL.'<!-- ==================== article '.$cpt.'============== -->'.PHP_EOL;
echo "<div class=\"article\" id=\"article-$cpt\" style=\"display: none;\">\n";
echo "<hr>";
echo "<a name=\"article-$cpt\">";
$article_only = $article['content'];
$temp = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only);
$article_only = $temp;
$temp = preg_replace('/\s\s+/', ' ', $article_only);
$article_only = $temp;
$re='/<div data-iframely-id="(.+?)" data-embedded-url="https:\/\/www.youtube.com\/watch\?v=(.+?)"(.+?)>/';
$newre='<div><iframe width="100%" src="https://www.youtube.com/embed/\\2?feature=oembed" frameborder="0" gesture="media" allowfullscreen></iframe>';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/<div data-iframely-id="(.+?)" data-embedded-url="https:\/\/www.youtube.com\/watch\?time_continue=(.+?)&v=(.+?)"(.+?)>/';
$newre='<div><iframe width="100%" src="https://www.youtube.com/embed/\\3?feature=oembed&start=\\2" frameborder="0" gesture="media" allowfullscreen></iframe>';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/><iframe data-img="" data-iframely-url="(.+?)" style="(.+?)"><\/iframe>/';
$newre='<a href="\\1" target="new">Video</a><iframe width="100%" src="https:\\1" frameborder="0" gesture="media" allowfullscreen></iframe>';
$article_only = preg_replace($re, $newre, $article_only);
$re = '/<div style="left:0;width:100%;height:0;position:relative;padding-bottom:56.2493%;" data-iframely-smart-iframe="true"/';
$article_only = preg_replace($re, '<div>', $article_only);
$re='/<div style="max-width: (.+?)px;"/';
$newre='<div ';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/<div style="left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.(.+?)" data-iframely-smart-iframe="true">/';
$newre='<div>';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/<div data-iframely-id="(.+?)" data-embedded-url="https:\/\/www.youtube.com\/embed\/(.+?)"(.+?)>/';
$newre='<div><iframe width="100%" src="https://www.youtube.com/embed/\\2" frameborder="0" gesture="media" allowfullscreen></iframe>';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/<div data-iframely-id="(.+?)" data-embedded-url="https:\/\/twitter.com\/(.+?)"(.+?)>/';
$newre='<div><iframe width="100%" src="https://publish.twitter.com/oembed?https://twitter.com/\\2"></iframe>';
$temp = preg_replace($re, $newre, $article_only);
$article_only = $temp;
$re='/<source media="\(max-width: (.+?)\)" /';
$temp = preg_replace($re, '<source media="(max-width: 100%)" ', $article_only);
$article_only = $temp;
$re='/<source media="\(min-width: (.+?)\)" /';
$temp = preg_replace($re, '<source media="(min-width: 100%)" ', $article_only);
$article_only = $temp;
$re='/<img src="(.+?)" alt="">/';
$temp = preg_replace($re, '<img width="100%" src="\\1" alt="">" ', $article_only);
$article_only = $temp;
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
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;
echo '<button id="html-btn" onclick="printHTML()" style="display:inline;"><img src="img/html5.png" width="24px" height="24px"></button>'.PHP_EOL;
echo '<button id="pdf-btn" onclick="printPDF()" style="display:inline;"><img src="img/pdf.png" width="24px" height="24px"></button>'.PHP_EOL;
echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div>'.PHP_EOL;
echo '<div class="extract-content" id="'.$cpt.'"><h1>'.$article['title'].'</h1>'.$article_only.'</div>'.PHP_EOL;
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> '.PHP_EOL;
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;
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;
echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> '.PHP_EOL;
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;
echo '<!-- ENDOF ==================== article '.$cpt.'============== -->'.PHP_EOL;
$cpt++;
if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
break;
}
}
?>