diff --git a/epub.php b/epub.php index 3f07262..ec9c7ee 100644 --- a/epub.php +++ b/epub.php @@ -397,6 +397,71 @@ write_epub($epub); } + // Politis RSS + if (isset($_POST['politis']) && $_POST['politis']) + { + $issuenb = ''; + if (isset($_POST['politisnb'])) + { + $issuenb = $_POST['politisnb']; + } + $feedurl = 'https://www.politis.fr/flux-rss-politis-fr/'; + $opts = [ + 'http' => [ + 'method' => "GET", + //'header' => "Accept-language: en\nCookie: MPSESSID=" . $mp_sessionid, // todo + ] + ]; + $context = stream_context_create($opts); + + // todo add cover! + + $epub = new TPEpubCreator(); + $epub->temp_folder = 'temp/'; + $epub->epub_file = 'epub/politis' . $issuenb . '.epub'; + $epub->title = 'Politis ' . $issuenb . ' - RSS ' . $today; + + // load feeds + $feed = file_get_contents($feedurl); + $xml = new SimpleXMLElement($feed); + $items = $xml->xpath("/rss/channel/item"); + + // reverse to respect timing + foreach (array_reverse($items) as $item) + { + $url = $item->link; + $article = file_get_contents($url, false, $context); + + if ($issuenb && !str_contains($article, ' dans l’hebdo N° ' . $issuenb)) + { + continue; + } + + $doc = new DOMDocument(); + $doc->loadHTML($article); + $finder = new DomXPath($doc); + + $title = $finder->query('//h1')->item(0)->textContent; + $author = $finder->query('//span[@class="nom"]')->item(0)->textContent; + $date = $finder->query('//span[@class="date"]')->item(0)->textContent; + $summary = $finder->query('//div[@class="extrait"]')->item(0)->textContent; + + $result = '
' . $author . '
'; + $result .= '' . $date . '
'; + $result .= '' . $summary . '
'; + + $nodes = $finder->query('//div[@id="content"]'); + $node = $nodes->item(0); + $nodehtml = get_clean_html($node); + $result .= $nodehtml; + $epub->AddPage($result, false, $title); + + } + + write_epub($epub); + } + // Mediapart home page if (isset($_POST['mphome']) && $_POST['mphome']) { @@ -591,6 +656,11 @@ +