<?php

class NewsSourceZdechovNET extends NewsSource
{

  function Import(): string
  {
    $Output = parent::Import();
    $Content = file_get_contents_curl($this->URL);

    $BlockStart = '<strong>Novinky:</strong>';
    $BlockEnd = '</table>';
    $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
    if ($Content == '')
    {
      $Output .= 'Main block not isolated.</br>';
      return $Output;
    }

    $ItemStart = '<div>';
    $ItemEnd = '</div>';
    while (strpos($Content, $ItemStart) !== false)
    {
      $Item = GetTextBetween($Content, $ItemStart, $ItemEnd);
      $NewsItem = new NewsItem();

      $NewsItem->Link = 'https://www.zdechov.net';
      $NewsItem->Title = GetTextBetween($Item, '<strong>', '</strong>');
      $Date = GetTextBetween($Item, '<strong>(', ')</strong>');
      $NewsItem->Date = HumanDateToTime($Date);
      $NewsItem->Category = $this->Category;
      $NewsItem->Content = html_entity_decode(GetTextBetween($Item, '<br/>', ''));
      $NewsItem->Author = 'Automat';
      $NewsItem->Database = $this->Database;
      $this->NewsItems[] = $NewsItem;
    }
    return $Output;
  }
}
