Compare commits

..

No commits in common. "545507773a69e5cfc94fcff566dfef03b83326e6" and "968339cfd900d973442cdba1642e3309414e65b7" have entirely different histories.

1 changed files with 13 additions and 50 deletions

View File

@ -19,17 +19,10 @@
function write_epub($epub) function write_epub($epub)
{ {
if (file_exists($epub->epub_file)) if ( ! $epub->error ) {
{
unlink($epub->epub_file);
}
if (!$epub->error)
{
$epub->CreateEPUB(); $epub->CreateEPUB();
if (!$epub->error) if ( ! $epub->error ) {
{
echo 'Success: <a href="' . $epub->epub_file . '">' . $epub->epub_file . '</a> created.<br>'; echo 'Success: <a href="' . $epub->epub_file . '">' . $epub->epub_file . '</a> created.<br>';
} }
else else
@ -37,9 +30,7 @@
echo $epub->error; echo $epub->error;
} }
} } else {
else
{
echo $epub->error; echo $epub->error;
} }
} }
@ -50,10 +41,9 @@
// Le Monde // Le Monde
if (isset($_POST['lemonde']) && $_POST['lemonde']) if (isset($_POST['lemonde']) && $_POST['lemonde'])
{ {
// parameters hardcoded for now // hardcoded for now
$includeimages = true; $includeimages = true;
$includepages = true; $includecover = false;
$url = $_POST['lmurl']; $url = $_POST['lmurl'];
// extract url from curl command // extract url from curl command
@ -68,6 +58,13 @@
$epub->epub_file = 'epub/lemonde.epub'; $epub->epub_file = 'epub/lemonde.epub';
$epub->title = 'Le Monde ' . $date ; $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 // cache json in case url expires
$tempjsonpath = 'temp/' . hash('md5', $url) . '.json'; $tempjsonpath = 'temp/' . hash('md5', $url) . '.json';
$json = ''; $json = '';
@ -85,38 +82,8 @@
$content = array_filter($publication->Content, function($item) { return $item->Category == 'Le Monde'; }); $content = array_filter($publication->Content, function($item) { return $item->Category == 'Le Monde'; });
usort($content, function ($a, $b) { return $a->PageNumber - $b->PageNumber; }); 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) 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('<img src="' . $tempimgpath . '">', 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_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; });
$articlebody = array_values($articlebody)[0]; $articlebody = array_values($articlebody)[0];
@ -150,15 +117,11 @@
$tempimgpath = './temp/' . $imageid . '.jpg'; $tempimgpath = './temp/' . $imageid . '.jpg';
$tempcontent = file_get_contents($imageurl); $tempcontent = file_get_contents($imageurl);
file_put_contents($tempimgpath, $tempcontent); file_put_contents($tempimgpath, $tempcontent);
$pagecontent .= '<p><img src="' . $tempimgpath . '"></p>'; $pagecontent .= '<div><img src="' . $tempimgpath . '"></div>';
} }
} }
$pagecontent .= $articlebody->HtmlText; $pagecontent .= $articlebody->HtmlText;
// debug
// echo '<pre style="white-space: pre-wrap;">' . $pagecontent . '<br>----------------------</pre>';
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true); $epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true);
} }
} }