1 contributor
<?php
include_once( 'news-constants.php' );
$rss_content = file_get_contents(NEWS_RSS_HUFFINGTONPOSTFR);
$orgStrings = array( 'media:content');
$newStrings = array( 'mediacontent');
$rss_content = str_replace($orgStrings, $newStrings, $rss_content);
$xml = simplexml_load_string($rss_content);
if ($xml === false) {
echo 'Failed to read RSS';
} else {
$channel = array();
$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'] . '</h4>';
$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;
$SEARCH_SUB1='<p><img width="1024" height="';
$pos_start = strpos($item->description, $SEARCH_SUB1);
$pos_start += strlen($SEARCH_SUB1);
$SEARCH_SUB2="\"";
$pos_stop = strpos($item->description, $SEARCH_SUB2, $pos_start);
$height=substr($item->description, $pos_start, $pos_stop - $pos_start);
$article['width']=1024;
$article['height']=$height;
$SEARCH_SUB1='src="';
$pos_start = strpos($item->description, $SEARCH_SUB1);
$pos_start += strlen($SEARCH_SUB1);
$SEARCH_SUB2="\"";
$pos_stop = strpos($item->description, $SEARCH_SUB2, $pos_start);
$article['image']=$item->mediacontent['url'];
$articles[$cpt] = $article;
echo '<div onclick="onArticle('.$cpt.')" style="display:inline;">'.PHP_EOL;
echo '<img src="'.$article['image'].'" style="display:inline;" width="100%"><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 class="col-6">';
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\">\n";
$article_content = file_get_contents($article['link']);
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$libxml_previous_state = libxml_use_internal_errors(true);
$doc->loadHTML($article_content);
libxml_clear_errors();
libxml_use_internal_errors($libxml_previous_state);
$articles = $doc->getElementsByTagName('article');
foreach ( $articles as $node) {
$article_only = DOMinnerHTML($node);
}
$orgStrings = array( '<img src="',
'style="width: 680px"',
'<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>',
' width="500" height="281" frameborder="0" ');
$newStrings = array( '<img width="100%" src="',
'style="width: 100%"',
'',
' width="100%" frameborder="0" ');
$article_only = str_replace($orgStrings, $newStrings, $article_only);
$SEARCH_SUB1='<p><strong>Lire aussi :</strong></p>';
$pos_stop = strpos($article_only, $SEARCH_SUB1);
if($pos_stop) {
$temp = substr($article_only, 0, $pos_stop);
$article_only = $temp."</blockquote>";
} else {
//End of article cleanup
$SEARCHSUB='<h3 class="related-entries__title">LIRE AUSSI</h3>';
$pos_stop=false;
$pos_stop = strpos($article_only, $SEARCHSUB);
if($pos_stop) {
$temp = substr($article_only, 0, $pos_stop);
$article_only = $temp;
} else {
$SEARCHSUB='<h3 class="recirc__title trending">';
$pos_stop=false;
$pos_stop = strpos($article_only, $SEARCHSUB);
if($pos_stop) {
$temp = substr($article_only, 0, $pos_stop);
$article_only = $temp;
} else {
DEBUG("Article($cpt) : No Match");
}
}
}
$re = '/alt="(.+?)" width="(.+?)" height="(.+?)"/';
$temp = preg_replace($re, 'width="100%"', $article_only);
$article_only = $temp;
$re = '/alt="" width="(.+?)" height="(.+?)"/';
$temp = preg_replace($re, 'width="100%"', $article_only);
$article_only = $temp;
$re = '/<iframe width="500" height="(.+?)"/';
$temp = preg_replace($re, '<iframe width="100%"', $article_only);
$article_only = $temp;
$re = '/sizes="\(max-width: (.+?)\) 100vw, (.+?)"/';
$temp = preg_replace($re, 'sizes="(max-width: 100%) 100vw,100%"', $article_only);
$article_only = $temp;
$re = '/<figure id="attachment_(.+?)" style="width: (.+?)" class="wp-caption aligncenter">/';
$temp = preg_replace($re, '<figure id="attachment_\\1" style="width: 100%" class="wp-caption aligncenter">', $article_only);
$article_only = $temp;
$re = '/<img class="aligncenter size-full wp-image-(.+?)"/';
$temp = preg_replace($re, '<img ', $article_only);
$article_only = $temp;
$re = '/<iframe (.+?) height="(.+?)" (.+?) width="(.+?)">/';
$temp = preg_replace($re, '<iframe \\1 \\3 width="100%">', $article_only);
$article_only = $temp;
$re = '/<img class="image__src"/';
$temp = preg_replace($re, '<img class="image__src" width="100%"', $article_only);
$article_only = $temp;
$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;
$orgStrings = array(
'<div id="entry_paragraph_1" class="entry-body--paragraph-ad"> <div class="ad_spot "> </div> </div>',
'<div id="entry_paragraph_2" class="entry-body--paragraph-ad"> <div class="ad_spot "> </div> </div>',
'<div id="entry_paragraph_3" class="entry-body--paragraph-ad"> <div class="ad_spot "> </div> </div>',
'<div id="entry_paragraph_4" class="entry-body--paragraph-ad"> <div class="ad_spot "> </div> </div>');
$newStrings = array(
'',
'',
'',
'');
$article_only = str_replace($orgStrings, $newStrings, $article_only);
// Cleanup "Social"
$re='/<script id="share-bar__social-mob" (.+)<\/script>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<li class="(facebook|twitter|gplus|pinterest|linkedin|email) share-bar__item">(.+)<\/a><\/li>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<li class="(facebook|twitter|snapchat|instagram) follow-us-networks-item " (.+?)<\/span> <\/a> <\/li>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<div class="social-overlay__qr">(.+)<\/a><\/div>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<script type="text\/javascript"> \(function\(\)\{ var dfp_placement_slug(.+)<\/script>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<form class="newsletter-signup" method="POST">(.+)<\/form>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<div class="follow-us__header"> <h3>SUIVEZ-NOUS<\/h3> <\/div>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<div class="follow-us__description"> <p>Avec la newsletter quotidienne du HuffPost(.+) target="_blank">En savoir plus<\/a> <\/p> <\/div>/';
$article_only = preg_replace($re, '', $article_only);
$re='/<li class="(facebook|instagram) follow-us-networks-item even" (.+) <\/a> <\/li>/';
$article_only = preg_replace($re, '', $article_only);
//Clean Empty lines
$article_only = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only);
$article_only = preg_replace('/\s\s+/', ' ', $article_only);
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 '<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.'">';
echo '<h4>'.$article['title'].'</h4>';
echo $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-upi 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;
}
}
?>