Compare commits

..

3 Commits

Author SHA1 Message Date
quenousimporte f5cc7bdb86 add politis 2024-09-04 17:43:51 +02:00
quenousimporte 67dc9411e4 keep strong tag 2024-09-04 17:43:37 +02:00
quenousimporte 3154d19435 add a link to generation page on index 2024-09-04 17:43:22 +02:00
2 changed files with 72 additions and 1 deletions

View File

@ -21,7 +21,7 @@
$nodeHTML = str_replace('</aside', '</i></b', $nodeHTML); $nodeHTML = str_replace('</aside', '</i></b', $nodeHTML);
$innerHTML .= $nodeHTML; $innerHTML .= $nodeHTML;
} }
return '<div>' . strip_tags($innerHTML, '<p><b><h2><i>') . '</div>'; return '<div>' . strip_tags($innerHTML, '<p><b><h2><i><strong>') . '</div>';
} }
function add_mp_article($url, $context, $epub) function add_mp_article($url, $context, $epub)
@ -397,6 +397,71 @@
write_epub($epub); 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 lhebdo 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 = '<h1>' . $title . '</h1>';
$result .= '<p>' . $author . '</p>';
$result .= '<p>' . $date . '</p>';
$result .= '<p><b>' . $summary . '</b></p>';
$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 // Mediapart home page
if (isset($_POST['mphome']) && $_POST['mphome']) if (isset($_POST['mphome']) && $_POST['mphome'])
{ {
@ -591,6 +656,11 @@
<input id="nyttoday" name="nyttoday" type="checkbox"> <input id="nyttoday" name="nyttoday" type="checkbox">
<label for="nyttoday">From today's paper embedded script</label> <label for="nyttoday">From today's paper embedded script</label>
<h2>Politis</h2>
<input id="politis" name="politis" type="checkbox">
<label for="politis">From RSS.</label>
<label for="politisnb">Optional issue number: </label><input id="politisnb" name="politisnb">
<h2>Admin</h2> <h2>Admin</h2>
<input id="emptycache" name="emptycache" type="checkbox" checked> <input id="emptycache" name="emptycache" type="checkbox" checked>
<label for="emptycache">Empty cache</label> <label for="emptycache">Empty cache</label>

View File

@ -68,6 +68,7 @@
<li><a href="https://www.cairn.info/revue-ecorev.htm">Eco Rev'</a></li> <li><a href="https://www.cairn.info/revue-ecorev.htm">Eco Rev'</a></li>
</ul> </ul>
<li><a href="./epub">Fichiers epub</a></li> <li><a href="./epub">Fichiers epub</a></li>
<li><a href="./epub.php">Génération epub</a></li>
</ul> </ul>
</body> </body>
</html> </html>