refactor json caching
This commit is contained in:
parent
df3c954ab4
commit
ce0f0ec37a
34
epub.php
34
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 = '<h1>' . $article->title . '</h1>';
|
||||
//$content .= '<b>' . $article->abstract . '</b>';
|
||||
|
|
Loading…
Reference in New Issue