Compare commits
3 Commits
bf56f2e120
...
158fa4c51a
Author | SHA1 | Date |
---|---|---|
quenousimporte | 158fa4c51a | |
quenousimporte | 74f6fed923 | |
quenousimporte | 19657ef92f |
139
epub.php
139
epub.php
|
@ -97,16 +97,10 @@
|
||||||
date_default_timezone_set('Europe/Paris');
|
date_default_timezone_set('Europe/Paris');
|
||||||
$date = (new DateTime('today'))->format('Ymd');
|
$date = (new DateTime('today'))->format('Ymd');
|
||||||
|
|
||||||
// Socialter
|
// Cafeyn
|
||||||
/*if (isset($_POST['socialter']) && $_POST['socialter'])
|
if (isset($_POST['cafeyn']) && $_POST['cafeyn'])
|
||||||
{
|
{
|
||||||
// parameters hardcoded for now
|
$url = $_POST['cafeynurl'];
|
||||||
$includeimages = false;
|
|
||||||
$includepages = true;
|
|
||||||
$imagesonly = false;
|
|
||||||
$imagesize = $imagesonly ? "XLARGE" : "MEDIUM";
|
|
||||||
|
|
||||||
$url = $_POST['socurl'];
|
|
||||||
|
|
||||||
// extract url from curl command
|
// extract url from curl command
|
||||||
if (str_starts_with($url, 'curl '))
|
if (str_starts_with($url, 'curl '))
|
||||||
|
@ -115,11 +109,6 @@
|
||||||
echo '<p>extracted url from curl command:</p><p>' . $url . '</p>';
|
echo '<p>extracted url from curl command:</p><p>' . $url . '</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$epub = new TPEpubCreator();
|
|
||||||
$epub->temp_folder = 'temp/';
|
|
||||||
$epub->epub_file = 'epub/socialter.epub';
|
|
||||||
$epub->title = 'Socialter ' . $date ;
|
|
||||||
|
|
||||||
// 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 = '';
|
||||||
|
@ -134,89 +123,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$publication = json_decode($json);
|
$publication = json_decode($json);
|
||||||
$content = array_filter($publication->Content, function($item) { return $item->Category == 'Le Monde'; });
|
$pubname = $publication->metadata->title;
|
||||||
usort($content, function ($a, $b) { return $a->PageNumber - $b->PageNumber; });
|
|
||||||
|
|
||||||
if ($includepages)
|
$epub = new TPEpubCreator();
|
||||||
|
$epub->temp_folder = 'temp/';
|
||||||
|
$epub->epub_file = 'epub/' . $pubname . '.epub';
|
||||||
|
$epub->title = $pubname . ' ' . $date ;
|
||||||
|
|
||||||
|
$list = (array)$publication->articles;
|
||||||
|
foreach ($list as $entry)
|
||||||
{
|
{
|
||||||
$pageindex = json_decode(file_get_contents(str_replace('GetPublicationContentItems', 'GetPublicationPages', $url)));
|
$articleurl = str_replace('material', 'article/' . $entry->hash . '.json', $url);
|
||||||
}
|
$articlejson = file_get_contents($articleurl);
|
||||||
|
$article = json_decode($articlejson);
|
||||||
$page = 0;
|
$epub->AddPage($article->title, false, $article->title);
|
||||||
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;
|
|
||||||
|
|
||||||
$path = lm_download_image($url, 'Preview-' . $imagesize . '-', $pageid);
|
|
||||||
|
|
||||||
if ($page == 1)
|
|
||||||
{
|
|
||||||
// cover
|
|
||||||
$epub->AddImage($path, 'image/jpeg', true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$epub->AddPage('<img style="width: 100%" src="' . $path . '">', false, 'Page ' . $page, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$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>';
|
|
||||||
$pagecontent .= '<p>Page ' . $article->PageNumber . '</p>';
|
|
||||||
|
|
||||||
$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>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($includeimages)
|
|
||||||
{
|
|
||||||
$images = array_values(array_filter($article->ContentItem, function($item) { return $item->ContentType == 'graphic/jpeg' || $item->ContentType == 'image/jpeg'; }));
|
|
||||||
foreach ($images as $image)
|
|
||||||
{
|
|
||||||
$path = lm_download_image($url, 'Image-MEDIUM-', $image->ContentItemId);
|
|
||||||
$pagecontent .= '<p><img style="width: 100%" src="' . $path . '"></p>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pagecontent .= $articlebody->HtmlText;
|
|
||||||
|
|
||||||
if (!$imagesonly)
|
|
||||||
{
|
|
||||||
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
write_epub($epub);
|
write_epub($epub);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
// Le Monde
|
// Le Monde
|
||||||
if (isset($_POST['lemonde']) && $_POST['lemonde'])
|
if (isset($_POST['lemonde']) && $_POST['lemonde'])
|
||||||
{
|
{
|
||||||
// parameters hardcoded for now
|
|
||||||
$includeimages = false;
|
|
||||||
$includepages = true;
|
|
||||||
$imagesonly = false;
|
|
||||||
$imagesize = $imagesonly ? "XLARGE" : "MEDIUM";
|
|
||||||
|
|
||||||
$url = $_POST['lmurl'];
|
$url = $_POST['lmurl'];
|
||||||
|
|
||||||
// extract url from curl command
|
// extract url from curl command
|
||||||
|
@ -248,10 +175,7 @@
|
||||||
$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)));
|
||||||
{
|
|
||||||
$pageindex = json_decode(file_get_contents(str_replace('GetPublicationContentItems', 'GetPublicationPages', $url)));
|
|
||||||
}
|
|
||||||
|
|
||||||
$page = 0;
|
$page = 0;
|
||||||
foreach ($content as $article)
|
foreach ($content as $article)
|
||||||
|
@ -266,7 +190,7 @@
|
||||||
}))[0];
|
}))[0];
|
||||||
$pageid = $pageobj->PublicationPageID;
|
$pageid = $pageobj->PublicationPageID;
|
||||||
|
|
||||||
$path = lm_download_image($url, 'Preview-' . $imagesize . '-', $pageid);
|
$path = lm_download_image($url, 'Preview-MEDIUM-', $pageid);
|
||||||
|
|
||||||
if ($page == 1)
|
if ($page == 1)
|
||||||
{
|
{
|
||||||
|
@ -298,22 +222,9 @@
|
||||||
{
|
{
|
||||||
$pagecontent .= '<b>' . $articlebody->Introduction . '</b>';
|
$pagecontent .= '<b>' . $articlebody->Introduction . '</b>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($includeimages)
|
|
||||||
{
|
|
||||||
$images = array_values(array_filter($article->ContentItem, function($item) { return $item->ContentType == 'graphic/jpeg' || $item->ContentType == 'image/jpeg'; }));
|
|
||||||
foreach ($images as $image)
|
|
||||||
{
|
|
||||||
$path = lm_download_image($url, 'Image-MEDIUM-', $image->ContentItemId);
|
|
||||||
$pagecontent .= '<p><img style="width: 100%" src="' . $path . '"></p>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pagecontent .= $articlebody->HtmlText;
|
$pagecontent .= $articlebody->HtmlText;
|
||||||
|
|
||||||
if (!$imagesonly)
|
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true);
|
||||||
{
|
|
||||||
$epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_epub($epub);
|
write_epub($epub);
|
||||||
|
@ -329,7 +240,7 @@
|
||||||
$settings = file_get_contents('settings.php');
|
$settings = file_get_contents('settings.php');
|
||||||
$settings = str_replace($old, $mp_sessionid, $settings);
|
$settings = str_replace($old, $mp_sessionid, $settings);
|
||||||
file_put_contents('settings.php', $settings);
|
file_put_contents('settings.php', $settings);
|
||||||
echo '<div>Updated mpsessid in settings</div>';
|
echo '<div>Updated mpsessid in settings.</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedurl = 'https://www.mediapart.fr/articles/feed';
|
$feedurl = 'https://www.mediapart.fr/articles/feed';
|
||||||
|
@ -577,15 +488,15 @@
|
||||||
<b>Le Monde</b>
|
<b>Le Monde</b>
|
||||||
<br>
|
<br>
|
||||||
<input id="lemonde" name="lemonde" type="checkbox">
|
<input id="lemonde" name="lemonde" type="checkbox">
|
||||||
<label for="lemonde">From json url: </label>
|
<label for="lemonde">From "GetPublicationContentItems" json url: </label>
|
||||||
<input name="lmurl"><br>
|
<input name="lmurl"><br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<b>Socialter</b>
|
<b>Cafeyn</b>
|
||||||
<br>
|
<br>
|
||||||
<input id="socialter" name="socialter" type="checkbox">
|
<input id="cafeyn" name="cafeyn" type="checkbox">
|
||||||
<label for="socialter">From json url: </label>
|
<label for="cafeyn">From "material" json url: </label>
|
||||||
<input name="socurl"><br>
|
<input name="cafeynurl"><br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<b>Mediapart</b>
|
<b>Mediapart</b>
|
||||||
|
|
Loading…
Reference in New Issue