2024-05-28 16:13:52 +02:00
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
|
2024-05-23 17:00:20 +02:00
|
|
|
<?php
|
|
|
|
|
2024-06-03 17:08:34 +02:00
|
|
|
require('settings.php');
|
2024-05-28 16:13:52 +02:00
|
|
|
|
|
|
|
if (isset($_POST['mpsessid']) && $_POST['mpsessid'])
|
|
|
|
{
|
2024-06-03 17:08:34 +02:00
|
|
|
$mp_sessionid = $_POST['mpsessid'];
|
|
|
|
echo 'Using ' . $mp_sessionid . '<br>';
|
2024-05-28 16:13:52 +02:00
|
|
|
}
|
|
|
|
|
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",
|
2024-06-03 17:08:34 +02:00
|
|
|
'header' => "Accept-language: en\nCookie: MPSESSID=" . $mp_sessionid,
|
2024-05-23 17:00:20 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$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-30 09:12:23 +02:00
|
|
|
// strip images
|
|
|
|
$toremove = $finder->query('//svg');
|
|
|
|
foreach ($toremove as $elt)
|
2024-05-24 15:01:56 +02:00
|
|
|
{
|
2024-05-30 09:12:23 +02:00
|
|
|
$elt->parentNode->removeChild($elt);
|
|
|
|
}
|
|
|
|
$toremove = $finder->query('//figure');
|
|
|
|
foreach ($toremove as $elt)
|
|
|
|
{
|
|
|
|
$elt->parentNode->removeChild($elt);
|
|
|
|
}
|
|
|
|
$toremove = $finder->query('//span[@class="screen-reader-only"]');
|
|
|
|
foreach ($toremove as $elt)
|
|
|
|
{
|
|
|
|
$elt->parentNode->removeChild($elt);
|
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-30 09:12:23 +02:00
|
|
|
$result .= '<div>' . strip_tags($innerHTML, '<p><b><h2><i>') . '</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-28 16:13:52 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<form method="post">
|
|
|
|
Force MPSESSID: <input name="mpsessid">
|
|
|
|
<input type="submit">
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|