format('Ymd'); if (isset($_POST['url'])) { require('TPEpubCreator.php'); $url = $_POST['url']; // extract url from curl command if (str_starts_with($url, 'curl ')) { $url = explode("'", $url)[1]; echo '

extracted url from curl command:

' . $url . '

'; } $epub = new TPEpubCreator(); $epub->temp_folder = 'temp/'; $epub->epub_file = 'epub/lemonde' . $date . '.epub'; $epub->title = 'Le Monde ' . $date ; 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'; $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; }); foreach ($content as $article) { $articlebody = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; }); $articlebody = array_values($articlebody)[0]; 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]; if ($author->Author) { $pagecontent .= $author->Author; } if ($articlebody->Introduction) { $pagecontent .= '' . $articlebody->Introduction . ''; } if ($lm_includeimages) { $images = array_values(array_filter($article->ContentItem, function($item) { return $item->ContentType == 'graphic/jpeg' || $item->ContentType == 'image/jpeg'; })); foreach ($images as $image) { $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)); } } if ( ! $epub->error ) { $epub->CreateEPUB(); if ( ! $epub->error ) { echo 'Success: ' . $epub->epub_file . ' created.
'; } else { echo $epub->error; } } else { echo $epub->error; } } // list existing files $files = glob('epub/*'); foreach ($files as $file) { echo '' . $file . '
'; } ?>
GetPublicationContentItems url: