2024-05-27 13:28:36 +02:00
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<?php
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
$url = '';
|
|
|
|
$coverurl = '';
|
|
|
|
if (isset($_POST['url']))
|
|
|
|
{
|
|
|
|
require('TPEpubCreator.php');
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
$url = $_POST['url'];
|
2024-05-28 16:13:52 +02:00
|
|
|
|
|
|
|
// extract url from curl command
|
|
|
|
if (str_starts_with($url, 'curl '))
|
|
|
|
{
|
|
|
|
$url = explode("'", $url)[1];
|
|
|
|
echo '<p>extracted url from curl command:</p><p>' . $url . '</p>';
|
|
|
|
}
|
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
$epub = new TPEpubCreator();
|
|
|
|
$epub->temp_folder = 'temp/';
|
|
|
|
$epub->epub_file = $_POST['epub'];
|
|
|
|
$epub->title = $_POST['title'];
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
if ($_POST['cover'])
|
|
|
|
{
|
|
|
|
$coverurl = $_POST['cover'];
|
|
|
|
$coverdata = file_get_contents($coverurl);
|
|
|
|
file_put_contents('temp/cover.jpg', $coverdata);
|
|
|
|
$epub->AddImage( 'temp/cover.jpg', 'image/jpeg', true );
|
|
|
|
}
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
// cache json in case url expires
|
|
|
|
$tempjsonpath = 'temp/' . hash('md5', $url) . '.json';
|
|
|
|
$json = '';
|
|
|
|
if (file_exists($tempjsonpath))
|
|
|
|
{
|
|
|
|
$json = file_get_contents($tempjsonpath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$json = file_get_contents($url);
|
|
|
|
file_put_contents($tempjsonpath, $json);
|
|
|
|
}
|
|
|
|
|
|
|
|
$publication = json_decode($json);
|
|
|
|
$content = array_filter($publication->Content, function($item) { return $item->Category == 'Le Monde'; });
|
|
|
|
usort($content, function ($a, $b) { return $a->PageNumber - $b->PageNumber; });
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
foreach ($content as $article)
|
|
|
|
{
|
|
|
|
$articlebody = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; })[0];
|
|
|
|
if ($articlebody->Title && $articlebody->HtmlText)
|
|
|
|
{
|
|
|
|
$pagecontent = '<h1>'. strip_tags($articlebody->Title) . '</h1>';
|
|
|
|
if ($articlebody->Introduction)
|
|
|
|
{
|
|
|
|
$pagecontent .= '<b>' . $articlebody->Introduction . '</b>';
|
|
|
|
}
|
|
|
|
$pagecontent .= $articlebody->HtmlText;
|
|
|
|
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title));
|
|
|
|
// echo('<h1>'. strip_tags($articlebody->Title) . '</h1>');
|
|
|
|
// echo($articlebody->HtmlText);
|
|
|
|
}
|
|
|
|
}
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
if ( ! $epub->error ) {
|
|
|
|
$epub->CreateEPUB();
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
if ( ! $epub->error ) {
|
|
|
|
echo 'Success: Download your book <a href="' . $epub->epub_file . '">here</a>.';
|
|
|
|
}
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
} else {
|
|
|
|
echo $epub->error;
|
|
|
|
}
|
|
|
|
}
|
2024-05-28 16:13:52 +02:00
|
|
|
|
2024-05-27 13:28:36 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<form method="post">
|
|
|
|
<p>Go to <a href="https://journal.lemonde.fr" target="_blank">https://journal.lemonde.fr</a> and hit f12 to get GetPublicationContentItems json and cover jpg urls.</p>
|
|
|
|
Json url: <input name="url" value="<?php echo $url; ?>"><br>
|
|
|
|
Cover url: <input name="cover" value="<?php echo $coverurl; ?>"><br>
|
|
|
|
Title: <input name="title" value="Le Monde"><br>
|
|
|
|
Epub file name: <input name="epub" value="lemonde.epub"><br>
|
|
|
|
<input type="submit">
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|