<?php 
include('view/new_header_file.php');
?>

<link rel="stylesheet" type="text/css" href="node_modules/css-toggle-switch/dist/toggle-switch.css">
<style type="text/css">
  #desp1, #cdesp > p
  {
    font-size: 16px;
  }
</style>

<?php 


$newsimages = array();
$completetitles = array();
$compeltedesparray = array();
$completetimearray = array();
$completehrefarray = array();

include('libs/simple_html_dom.php');
$html = file_get_html('https://www.reuters.com/news/archive/gca-foreignexchange?view=page&page=1&pageSize=15');

// Find all images 
foreach($html->find('section[class=module]') as $element){
  
  $mainNewsSection = $element;

  foreach ($mainNewsSection->find('section[class=module-content]') as $headlineContent) {
    # code...

    foreach ($headlineContent->find('div[class=news-headline-list]') as $divHeadlineContent) {
      
      foreach ($divHeadlineContent->find('article[class=story]') as $storyContent) {



    
      
      

        foreach ($storyContent->find('div[class=story-photo lazy-photo]') as $contStory) {
          # code...

          
          
          foreach ($contStory->find('a') as $getATag) {
            # code...

            $fullarray = array();

            foreach ($getATag->find('img') as $getimages) {
              # code...
              $var = 'org-src';

              $orgimagelink = $getimages->$var;

              $fullarray = array('img'=>$orgimagelink);

              array_push($newsimages, $fullarray);

                
            }
          }

        }








        foreach ($storyContent->find('div[class=story-content]') as $contStory) {
          # code...
          
          foreach ($contStory->find('a') as $aTagComplete) {
            # code...
            $hrefatag = $aTagComplete->href;

            $titlearray = array();

            $desparray = array();

            $timearray = array();
            

            $tagarray = array();


            $tagarray = array('ref'=>$hrefatag);

            array_push($completehrefarray, $tagarray);


            foreach ($aTagComplete->find('h3') as $headingPost) {
              # code...
              $stripTags = strip_tags($headingPost);

              $titles = array('title'=>$stripTags);

              array_push($completetitles, $titles);

            }

            
          }


          foreach ($contStory->find('p') as $despPost) {
              # code...
              $stripTagP = strip_tags($despPost);

              $desparray = array('desp'=>$stripTagP);

              array_push($compeltedesparray, $desparray);
          }



          foreach ($contStory->find('time') as $timePost) {
              # code...
            
            foreach ($timePost->find('span') as $spanTime) {
              # code...

              $stripTagTime = strip_tags($spanTime);

              $timearray = array('time'=>$stripTagTime);

              array_push($completetimearray, $timearray);
            }

          }


        }








      }

    }


  }


} 



?>


      <div class="container-fluid">
              <?php 
                  include('view/news.view.php');
              ?>
    </div>


<?php
include('view/new_footer_file.php');
?>


<script type="text/javascript">
  function postShow(title, url, imgurl)
  {
      $("#newsTitle").html(title);

      var fullurl = "https://www.reuters.com"+ url;

      $("#cdesp").html('');
      $("#desp1").html('');

      $("#postimg").attr('src', imgurl);

        $.ajax({
          type: 'POST',
          url: 'controller/post.controller.php', 
          data: {url:fullurl},
          success: function(res){
            
            var result = JSON.parse(res);

            for (var i = 0; i < result.length; i++) {

                  
                  if (i == 0) {

                      $("#desp1").html(result[i]);

                  }else{

                    var d = '<p>'+result[i]+'</p>';

                    $("#cdesp").append(d);

                  }

            }

          }

    });




  }
</script>