news
/
sources
/
news-huffingtonpost.fr.php
/
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;">';
echo '<img src="'.$article['image'].'" style="display:inline;" width="100%"><br>';
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> ';
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'].' ';
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>';
$cpt++;
if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
break;
}
}
}
echo ' </div><!-- ./panel-body -->';
echo ' </div><!-- ./panel panel-default -->';
echo ' </div><!-- ./col-md-6 -->';
echo '<div class="col-md-6">';
echo '<div class="panel panel-default">';
echo '<div class="panel-body">';
echo '<a name="article-top"></a><div id="article-current"></div>';
$cpt=0;
foreach ($articles as $article ) {
$cpt_prev=$cpt-1;
$cpt_next=$cpt+1;
echo "\n";
echo '<!-- ==================== article '.$cpt.'============== -->';
echo "\n";
echo "<div class=\"article\" id=\"article-$cpt\" style=\"display: none;\">\n";
echo "<hr>";
echo "<a name=\"article-$cpt\">";
$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>";
}
$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);
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> ';
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> ';
echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> ';
echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div>';
echo '<div class="extract-content" id="'.$cpt.'">';
echo '<h4>'.$article['title'].'</h4>';
echo $article_only.'</div>';
echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div> ';
echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-upi fa-2x"></i></a></div> ';
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> ';
echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div> ';
echo '<div id="nav-next" onclick="onArticle('.$cpt_next.')" style="display:inline;"><i class="fa fa-chevron-right fa-2x"></i></div></div>';
$cpt++;
if( $cpt > $NEWS_RSS_MAX_ITEMS ) {
break;
}
}
?>