Compare commits
No commits in common. "545507773a69e5cfc94fcff566dfef03b83326e6" and "968339cfd900d973442cdba1642e3309414e65b7" have entirely different histories.
545507773a
...
968339cfd9
63
epub.php
63
epub.php
|
@ -19,17 +19,10 @@
|
|||
|
||||
function write_epub($epub)
|
||||
{
|
||||
if (file_exists($epub->epub_file))
|
||||
{
|
||||
unlink($epub->epub_file);
|
||||
}
|
||||
|
||||
if (!$epub->error)
|
||||
{
|
||||
if ( ! $epub->error ) {
|
||||
$epub->CreateEPUB();
|
||||
|
||||
if (!$epub->error)
|
||||
{
|
||||
if ( ! $epub->error ) {
|
||||
echo 'Success: <a href="' . $epub->epub_file . '">' . $epub->epub_file . '</a> created.<br>';
|
||||
}
|
||||
else
|
||||
|
@ -37,9 +30,7 @@
|
|||
echo $epub->error;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo $epub->error;
|
||||
}
|
||||
}
|
||||
|
@ -50,10 +41,9 @@
|
|||
// Le Monde
|
||||
if (isset($_POST['lemonde']) && $_POST['lemonde'])
|
||||
{
|
||||
// parameters hardcoded for now
|
||||
// hardcoded for now
|
||||
$includeimages = true;
|
||||
$includepages = true;
|
||||
|
||||
$includecover = false;
|
||||
$url = $_POST['lmurl'];
|
||||
|
||||
// extract url from curl command
|
||||
|
@ -68,6 +58,13 @@
|
|||
$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 = '';
|
||||
|
@ -85,38 +82,8 @@
|
|||
$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('<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_values($articlebody)[0];
|
||||
|
||||
|
@ -150,15 +117,11 @@
|
|||
$tempimgpath = './temp/' . $imageid . '.jpg';
|
||||
$tempcontent = file_get_contents($imageurl);
|
||||
file_put_contents($tempimgpath, $tempcontent);
|
||||
$pagecontent .= '<p><img src="' . $tempimgpath . '"></p>';
|
||||
$pagecontent .= '<div><img src="' . $tempimgpath . '"></div>';
|
||||
}
|
||||
}
|
||||
|
||||
$pagecontent .= $articlebody->HtmlText;
|
||||
|
||||
// debug
|
||||
// echo '<pre style="white-space: pre-wrap;">' . $pagecontent . '<br>----------------------</pre>';
|
||||
|
||||
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue