From 2a8aec8d73ecc878d9f906b2638799462ccee3a1 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 3 Jun 2024 17:03:19 +0200 Subject: [PATCH] lm refactor --- lemonde.php | 57 ++++++++++++++++++++++++++++----------------- settings.php.sample | 4 ++++ 2 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 settings.php.sample diff --git a/lemonde.php b/lemonde.php index 807c543..c6659d3 100644 --- a/lemonde.php +++ b/lemonde.php @@ -3,14 +3,15 @@ format('Ymd'); if (isset($_POST['url'])) { require('TPEpubCreator.php'); $url = $_POST['url']; - $coverdate = $_POST['date']; // extract url from curl command if (str_starts_with($url, 'curl ')) @@ -21,11 +22,15 @@ $epub = new TPEpubCreator(); $epub->temp_folder = 'temp/'; - $epub->epub_file = 'lemonde' . $coverdate . '.epub'; - $epub->title = 'Le Monde ' . $coverdate ; + $epub->epub_file = 'epub/lemonde' . $date . '.epub'; + $epub->title = 'Le Monde ' . $date ; - $coverurl = 'https://www.lemonde.fr/thumbnail/journal/'. $coverdate .'/1000/1490'; - $epub->AddImage( $coverurl, 'image/jpeg', true ); + if ($lm_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'; @@ -52,6 +57,7 @@ if ($articlebody->Title && $articlebody->HtmlText) { $pagecontent = '

'. strip_tags($articlebody->Title) . '

'; + $pagecontent .= '

Page ' . $article->PageNumber . '

'; $author = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'author/xml'; }); $author = array_values($author)[0]; @@ -65,23 +71,26 @@ $pagecontent .= '' . $articlebody->Introduction . ''; } - /*$images = array_values(array_filter($article->ContentItem, function($item) { return $item->ContentType == 'graphic/jpeg' || $item->ContentType == 'image/jpeg'; })); - foreach ($images as $image) + if ($lm_includeimages) { - $imageid = $image->ContentItemId; - $imageurl = preg_replace('/GetPublicationContentItems-.*\.json/', 'Image-MEDIUM-' . $imageid . '.jpg', $url); - - $tempcontent = file_get_contents($imageurl); - file_put_contents('temp/' . $imageid, $tempcontent); - - //$epub->AddImage('temp/' . $imageid, false, false ); - - $pagecontent .= '
'; - if ($image->HtmlText) + $images = array_values(array_filter($article->ContentItem, function($item) { return $item->ContentType == 'graphic/jpeg' || $item->ContentType == 'image/jpeg'; })); + foreach ($images as $image) { - $pagecontent .= $image->HtmlText; + $imageid = $image->ContentItemId; + $imageurl = preg_replace('/GetPublicationContentItems-.*\.json/', 'Image-MEDIUM-' . $imageid . '.jpg', $url); + + $tempcontent = file_get_contents($imageurl); + file_put_contents('temp/' . $imageid, $tempcontent); + + //$epub->AddImage('temp/' . $imageid, false, false ); + + $pagecontent .= '
'; + if ($image->HtmlText) + { + $pagecontent .= $image->HtmlText; + } } - }*/ + } $pagecontent .= $articlebody->HtmlText; $epub->AddPage($pagecontent, false, strip_tags($articlebody->Title)); @@ -104,12 +113,18 @@ } } + // list existing files + $files = glob('epub/*'); + foreach ($files as $file) + { + echo '' . $file . '
'; + } + ?>

Go to https://journal.lemonde.fr, hit f12, open edition, and get GetPublicationContentItems json url.

Json url:
- Date:
diff --git a/settings.php.sample b/settings.php.sample new file mode 100644 index 0000000..0c466b2 --- /dev/null +++ b/settings.php.sample @@ -0,0 +1,4 @@ + \ No newline at end of file