diff --git a/epub.php b/epub.php index 7957d6b..ec98f0c 100644 --- a/epub.php +++ b/epub.php @@ -94,6 +94,23 @@ return $innerHTML; } + function get_json($url) + { + // cache json in case url expires + $tempjsonpath = 'temp/' . hash('md5', $url) . '.json'; + $json = ''; + if (file_exists($tempjsonpath)) + { + $json = file_get_contents($tempjsonpath); + } + else + { + $json = file_get_contents($url); + file_put_contents($tempjsonpath, $json); + } + return json_decode($json); + } + date_default_timezone_set('Europe/Paris'); $date = (new DateTime('today'))->format('Ymd'); @@ -110,19 +127,7 @@ } // cache json in case url expires - $tempjsonpath = 'temp/' . hash('md5', $url) . '.json'; - $json = ''; - if (file_exists($tempjsonpath)) - { - $json = file_get_contents($tempjsonpath); - } - else - { - $json = file_get_contents($url); - file_put_contents($tempjsonpath, $json); - } - - $publication = json_decode($json); + $publication = get_json($url); $pubname = $publication->metadata->title; $epub = new TPEpubCreator(); @@ -135,8 +140,7 @@ foreach ($list as $entry) { $articleurl = str_replace('material', 'article/' . $entry->hash . '.json', $url); - $articlejson = file_get_contents($articleurl); - $article = json_decode($articlejson); + $article = get_json($articleurl); $content = '

' . $article->title . '

'; //$content .= '' . $article->abstract . '';