2024-05-23 17:00:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$sessionid = 'value of cookie MPSESSID';
|
2024-05-28 12:12:41 +02:00
|
|
|
/*ini_set('display_errors', '1');
|
|
|
|
ini_set('display_startup_errors', '1');
|
|
|
|
error_reporting(E_ALL);*/
|
|
|
|
|
2024-05-27 14:29:24 +02:00
|
|
|
require('TPEpubCreator.php');
|
2024-05-23 17:00:20 +02:00
|
|
|
$feedurl = 'https://www.mediapart.fr/articles/feed';
|
|
|
|
$opts = [
|
|
|
|
'http' => [
|
|
|
|
'method' => "GET",
|
|
|
|
'header' => "Accept-language: en\nCookie: MPSESSID=" . $sessionid,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$context = stream_context_create($opts);
|
|
|
|
|
2024-05-27 14:29:24 +02:00
|
|
|
$epub = new TPEpubCreator();
|
|
|
|
$epub->temp_folder = 'temp/';
|
|
|
|
$epub->epub_file = 'mediapart.epub';
|
|
|
|
$epub->title = 'Mediapart';
|
|
|
|
|
2024-05-23 17:00:20 +02:00
|
|
|
// load feeds
|
|
|
|
$feed = file_get_contents($feedurl);
|
|
|
|
$xml = new SimpleXMLElement($feed);
|
|
|
|
$items = $xml->xpath("/rss/channel/item");
|
|
|
|
|
|
|
|
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR','fr','fr','fra','fr_FR@euro');
|
|
|
|
$localedate = strftime("%A %d %B %Y");
|
|
|
|
|
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
2024-05-24 15:01:56 +02:00
|
|
|
$title = $item->title;
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-24 15:01:56 +02:00
|
|
|
$category = $item->xpath('dc:subject')[0];
|
|
|
|
$author = $item->xpath('dc:creator')[0];
|
|
|
|
$summary = $item->description;
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-24 15:01:56 +02:00
|
|
|
$article = file_get_contents($item->link, false, $context);
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->loadHTML($article);
|
|
|
|
$finder = new DomXPath($doc);
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
$svgs = $finder->query('//svg');
|
|
|
|
foreach ($svgs as $svg)
|
2024-05-24 15:01:56 +02:00
|
|
|
{
|
2024-05-28 12:12:41 +02:00
|
|
|
$svg->parentNode->removeChild($svg);
|
2024-05-24 15:01:56 +02:00
|
|
|
}
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
$result = '<h1>' . $title . '</h1>';
|
|
|
|
$result .= '<p>' . $author . '</p>';
|
|
|
|
$result .= '<p>' . $item->pubDate . '</p>';
|
|
|
|
$result .= '<p><b>' . $summary . '</b></p>';
|
|
|
|
|
|
|
|
$nodes = $finder->query('//div[contains(@class, "paywall-restricted-content")]');
|
|
|
|
if (!$nodes->length)
|
2024-05-24 15:01:56 +02:00
|
|
|
{
|
2024-05-28 12:12:41 +02:00
|
|
|
// articles accès libre
|
|
|
|
$nodes = $finder->query('//div[contains(@class, "news__body__center__article")]');
|
2024-05-24 15:01:56 +02:00
|
|
|
}
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
if (!$nodes->length)
|
2024-05-24 15:01:56 +02:00
|
|
|
{
|
2024-05-28 12:12:41 +02:00
|
|
|
echo 'warning: could not get content of "' . $title . '"<br>';
|
2024-05-23 17:00:20 +02:00
|
|
|
}
|
2024-05-28 12:12:41 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$node = $nodes->item(0);
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
$innerHTML = '';
|
|
|
|
foreach ($node->childNodes as $childNode){
|
|
|
|
$innerHTML .= $childNode->ownerDocument->saveHTML($childNode);
|
|
|
|
}
|
|
|
|
$outerHTML = $node->ownerDocument->saveHTML($node);
|
|
|
|
$textcontent = $node->textContent;
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
$result .= '<div>' . $innerHTML . '</div>';
|
2024-05-27 14:29:24 +02:00
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
$epub->AddPage($result, false, $title);
|
|
|
|
}
|
2024-05-27 14:29:24 +02:00
|
|
|
|
|
|
|
|
2024-05-28 12:12:41 +02:00
|
|
|
//echo $result;
|
2024-05-27 14:29:24 +02:00
|
|
|
//break;
|
2024-05-23 17:00:20 +02:00
|
|
|
}
|
|
|
|
|
2024-05-27 14:29:24 +02:00
|
|
|
if ( ! $epub->error )
|
|
|
|
{
|
|
|
|
$epub->CreateEPUB();
|
2024-05-23 17:00:20 +02:00
|
|
|
|
2024-05-27 14:29:24 +02:00
|
|
|
if ( ! $epub->error ) {
|
|
|
|
echo 'Success: Download your book <a href="' . $epub->epub_file . '">here</a>.';
|
|
|
|
}
|
2024-05-23 17:00:20 +02:00
|
|
|
|
2024-05-27 14:29:24 +02:00
|
|
|
} else {
|
|
|
|
echo $epub->error;
|
|
|
|
}
|
2024-05-23 13:59:38 +02:00
|
|
|
?>
|