diff --git a/epub.php b/epub.php index 325db37..79b2130 100644 --- a/epub.php +++ b/epub.php @@ -97,16 +97,10 @@ date_default_timezone_set('Europe/Paris'); $date = (new DateTime('today'))->format('Ymd'); - // Socialter - /*if (isset($_POST['socialter']) && $_POST['socialter']) + // Cafeyn + if (isset($_POST['cafeyn']) && $_POST['cafeyn']) { - // parameters hardcoded for now - $includeimages = false; - $includepages = true; - $imagesonly = false; - $imagesize = $imagesonly ? "XLARGE" : "MEDIUM"; - - $url = $_POST['socurl']; + $url = $_POST['cafeynurl']; // extract url from curl command if (str_starts_with($url, 'curl ')) @@ -115,11 +109,6 @@ echo '

extracted url from curl command:

' . $url . '

'; } - $epub = new TPEpubCreator(); - $epub->temp_folder = 'temp/'; - $epub->epub_file = 'epub/socialter.epub'; - $epub->title = 'Socialter ' . $date ; - // cache json in case url expires $tempjsonpath = 'temp/' . hash('md5', $url) . '.json'; $json = ''; @@ -134,79 +123,23 @@ } $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; }); + $pubname = $publication->metadata->title; - 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))); - } - - $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; - - $path = lm_download_image($url, 'Preview-' . $imagesize . '-', $pageid); - - if ($page == 1) - { - // cover - $epub->AddImage($path, 'image/jpeg', true); - } - else - { - $epub->AddPage('', 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 = '

'. 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 ($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 .= '

'; - } - } - $pagecontent .= $articlebody->HtmlText; - - if (!$imagesonly) - { - $epub->AddPage($pagecontent, false, strip_tags($articlebody->Title), true); - } - } + $articleurl = str_replace('material', 'article/' . $entry->hash . '.json', $url); + $articlejson = file_get_contents($articleurl); + $article = json_decode($articlejson); + $epub->AddPage($article->title, false, $article->title); } write_epub($epub); - }*/ + } // Le Monde if (isset($_POST['lemonde']) && $_POST['lemonde']) @@ -559,11 +492,11 @@

- Socialter + Cafeyn
- - -
+ + +

Mediapart