le monde add each page preview + cover
This commit is contained in:
		
							parent
							
								
									968339cfd9
								
							
						
					
					
						commit
						7c2d9c92d3
					
				
							
								
								
									
										48
									
								
								epub.php
								
								
								
								
							
							
						
						
									
										48
									
								
								epub.php
								
								
								
								
							| 
						 | 
					@ -41,9 +41,10 @@
 | 
				
			||||||
	// Le Monde
 | 
						// Le Monde
 | 
				
			||||||
	if (isset($_POST['lemonde']) && $_POST['lemonde'])
 | 
						if (isset($_POST['lemonde']) && $_POST['lemonde'])
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// hardcoded for now
 | 
							// parameters hardcoded for now
 | 
				
			||||||
		$includeimages = true;
 | 
							$includeimages = true;
 | 
				
			||||||
		$includecover = false;
 | 
							$includepages = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$url = $_POST['lmurl'];
 | 
							$url = $_POST['lmurl'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// extract url from curl command
 | 
							// extract url from curl command
 | 
				
			||||||
| 
						 | 
					@ -58,13 +59,6 @@
 | 
				
			||||||
		$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 = '';
 | 
				
			||||||
| 
						 | 
					@ -82,8 +76,38 @@
 | 
				
			||||||
		$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];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -117,11 +141,15 @@
 | 
				
			||||||
						$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 .= '<div><img src="' . $tempimgpath . '"></div>';
 | 
											$pagecontent .= '<p><img src="' . $tempimgpath . '"></p>';
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				$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);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue