news / sources / news-numerama.fr.php /
d174392 7 years ago
1 contributor
135 lines | 7.293kb
<?php
include_once( 'news-constants.php' );

$rss_content = file_get_contents(NEWS_RSS_NUMERAMA);
$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']=substr($item->description, $pos_start, $pos_stop - $pos_start);
    $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>&nbsp;&nbsp;';
    echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-down fa-2x"></i></a></div>&nbsp;';
    echo $article['title'].'&nbsp;&nbsp;';
    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 '<!-- ==================== article '.$cpt.'============== -->';
  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']);
  $SEARCH_SUB1='<article class="post-content span8 tablet12 phone12">';
  $pos_start = strpos($article_content, $SEARCH_SUB1);
  $pos_start += strlen($SEARCH_SUB1);
  $SEARCH_SUB2='<div id="bottom_ad"';
  $pos_stop = strpos($article_content, $SEARCH_SUB2);
  $article_only = substr($article_content, $pos_start, $pos_stop - $pos_start);

  $orgStrings = array(' src="//www.numerama.com/');
  $newStrings = array(' src="https://www.numerama.com/');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);
  $orgStrings = array(' srcset="//www.numerama.com/');
  $newStrings = array(' srcset="https://www.numerama.com/');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);
  $orgStrings = array(' href="/');
  $newStrings = array(' href="https://www.numerama.com/');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);

  $orgStrings = array( ' width="500" height="281" frameborder="0" ');
  $newStrings = array( ' width="100%" frameborder="0" ');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);
  $orgStrings = array( 'style="width: 680px"');
  $newStrings = array( 'style="width: 100%"');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);
  $orgStrings = array( '<img src="');
  $newStrings = array( '<img width="100%" src="');
  $article_only  = str_replace($orgStrings, $newStrings, $article_only);
  $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;

  $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;
  echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  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.'">'.$article_only.'</div>';
  echo '<div class="extract-content" id="'.$cpt.'">';
  echo '<h4>'.$article['title'].'</h4><img width="100%" src="'.$article['image'].'" style="display:inline;"><br>';
  echo $article_only.'</div>';
  //$article_only = '<h4>'.$article['title'].'</h4><img src="'.$article['image'].'" style="display:inline;"><br>';
  echo '<div id="nav-up" style="display:inline;"><a href="#top"><i class="fa fa-home fa-2x"></i></a></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  echo '<div id="nav-up" style="display:inline;"><a href="#article-top"><i class="fa fa-chevron-upi fa-2x"></i></a></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  echo '<div id="nav-prev" onclick="onArticle('.$cpt_prev.')" style="display:inline;"><i class="fa fa-chevron-left fa-2x"></i></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  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;
  }
}
?>