From 7c2d9c92d3178c0986f69ec75e63880ad4d99b99 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 12 Jun 2024 10:54:18 +0200 Subject: [PATCH] le monde add each page preview + cover --- epub.php | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/epub.php b/epub.php index dfb7ed2..e56b0b6 100644 --- a/epub.php +++ b/epub.php @@ -41,9 +41,10 @@ // Le Monde if (isset($_POST['lemonde']) && $_POST['lemonde']) { - // hardcoded for now + // parameters hardcoded for now $includeimages = true; - $includecover = false; + $includepages = true; + $url = $_POST['lmurl']; // extract url from curl command @@ -58,13 +59,6 @@ $epub->epub_file = 'epub/lemonde.epub'; $epub->title = 'Le Monde ' . $date ; - if ($includecover) - { - // todo get correct cover according to date and time - $coverurl = 'https://www.lemonde.fr/thumbnail/journal/'. $date .'/1000/1490'; - $epub->AddImage( $coverurl, 'image/jpeg', true ); - } - // cache json in case url expires $tempjsonpath = 'temp/' . hash('md5', $url) . '.json'; $json = ''; @@ -82,8 +76,38 @@ $content = array_filter($publication->Content, function($item) { return $item->Category == 'Le Monde'; }); usort($content, function ($a, $b) { return $a->PageNumber - $b->PageNumber; }); + if ($includepages) + { + $pageindex = json_decode(file_get_contents(str_replace('GetPublicationContentItems', 'GetPublicationPages', $url))); + } + + $page = 0; foreach ($content as $article) { + if ($includepages && $article->PageNumber > $page) + { + $page = $article->PageNumber; + $pageobj = array_values(array_filter($pageindex->Page, function($p) + { + global $page; + return $page == $p->PageNumber; + }))[0]; + $pageid = $pageobj->PublicationPageID; + + // SMALL / MEDIUM / XLARGE + $pageurl = preg_replace('/GetPublicationContentItems-.*\.json/', 'Preview-MEDIUM-' . $pageid . '.jpg', $url); + $tempimgpath = './temp/' . $pageid . '.jpg'; + $tempcontent = file_get_contents($pageurl); + file_put_contents($tempimgpath, $tempcontent); + $epub->AddPage('', false, 'Page ' . $page, true); + + // Add page 1 as cover + if ($page == 1) + { + $epub->AddImage($tempimgpath, 'image/jpeg', true); + } + } + $articlebody = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; }); $articlebody = array_values($articlebody)[0]; @@ -117,11 +141,15 @@ $tempimgpath = './temp/' . $imageid . '.jpg'; $tempcontent = file_get_contents($imageurl); file_put_contents($tempimgpath, $tempcontent); - $pagecontent .= '
'; + $pagecontent .= '

'; } } $pagecontent .= $articlebody->HtmlText; + + // debug + // echo '
' . $pagecontent . '
----------------------
'; + $epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true); } }