le monde add author, compute date, attempt to add images
This commit is contained in:
parent
b9a6b7f956
commit
4de8dd9104
59
lemonde.php
59
lemonde.php
|
@ -4,12 +4,13 @@
|
|||
<?php
|
||||
|
||||
$url = '';
|
||||
$coverurl = '';
|
||||
$coverdate = '';
|
||||
if (isset($_POST['url']))
|
||||
{
|
||||
require('TPEpubCreator.php');
|
||||
|
||||
$url = $_POST['url'];
|
||||
$coverdate = $_POST['date'];
|
||||
|
||||
// extract url from curl command
|
||||
if (str_starts_with($url, 'curl '))
|
||||
|
@ -20,16 +21,11 @@
|
|||
|
||||
$epub = new TPEpubCreator();
|
||||
$epub->temp_folder = 'temp/';
|
||||
$epub->epub_file = $_POST['epub'];
|
||||
$epub->title = $_POST['title'];
|
||||
$epub->epub_file = 'lemonde' . $coverdate . '.epub';
|
||||
$epub->title = 'Le Monde ' . $coverdate ;
|
||||
|
||||
if ($_POST['cover'])
|
||||
{
|
||||
$coverurl = $_POST['cover'];
|
||||
$coverdata = file_get_contents($coverurl);
|
||||
file_put_contents('temp/cover.jpg', $coverdata);
|
||||
$epub->AddImage( 'temp/cover.jpg', 'image/jpeg', true );
|
||||
}
|
||||
$coverurl = 'https://www.lemonde.fr/thumbnail/journal/'. $coverdate .'/1000/1490';
|
||||
$epub->AddImage( $coverurl, 'image/jpeg', true );
|
||||
|
||||
// cache json in case url expires
|
||||
$tempjsonpath = 'temp/' . hash('md5', $url) . '.json';
|
||||
|
@ -50,18 +46,45 @@
|
|||
|
||||
foreach ($content as $article)
|
||||
{
|
||||
$articlebody = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; })[0];
|
||||
$articlebody = array_filter($article->ContentItem, function($item) { return $item->ContentType == 'text/xml'; });
|
||||
$articlebody = array_values($articlebody)[0];
|
||||
|
||||
if ($articlebody->Title && $articlebody->HtmlText)
|
||||
{
|
||||
$pagecontent = '<h1>'. strip_tags($articlebody->Title) . '</h1>';
|
||||
|
||||
$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 .= '<b>' . $articlebody->Introduction . '</b>';
|
||||
}
|
||||
|
||||
/*$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 .= '<div><img src="' . $imageurl . '"></div>';
|
||||
if ($image->HtmlText)
|
||||
{
|
||||
$pagecontent .= $image->HtmlText;
|
||||
}
|
||||
}*/
|
||||
|
||||
$pagecontent .= $articlebody->HtmlText;
|
||||
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title));
|
||||
// echo('<h1>'. strip_tags($articlebody->Title) . '</h1>');
|
||||
// echo($articlebody->HtmlText);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +94,10 @@
|
|||
if ( ! $epub->error ) {
|
||||
echo 'Success: Download your book <a href="' . $epub->epub_file . '">here</a>.';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $epub->error;
|
||||
}
|
||||
|
||||
} else {
|
||||
echo $epub->error;
|
||||
|
@ -80,11 +107,9 @@
|
|||
?>
|
||||
|
||||
<form method="post">
|
||||
<p>Go to <a href="https://journal.lemonde.fr" target="_blank">https://journal.lemonde.fr</a> and hit f12 to get GetPublicationContentItems json and cover jpg urls.</p>
|
||||
<p>Go to <a href="https://journal.lemonde.fr" target="_blank">https://journal.lemonde.fr</a> and hit f12 to get GetPublicationContentItems json url.</p>
|
||||
Json url: <input name="url" value="<?php echo $url; ?>"><br>
|
||||
Cover url: <input name="cover" value="<?php echo $coverurl; ?>"><br>
|
||||
Title: <input name="title" value="Le Monde"><br>
|
||||
Epub file name: <input name="epub" value="lemonde.epub"><br>
|
||||
Date: <input name="date" value="<?php echo $coverdate ? $coverdate : (new DateTime('tomorrow'))->format('Ymd'); /* or today if before 1pm */?>"><br>
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue