beta: media import
This commit is contained in:
parent
ff4fae57e9
commit
a840a715e6
1 changed files with 39 additions and 0 deletions
|
@ -550,6 +550,45 @@ class VroumVroum_Blog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MEDIA IMPORT PROCESSING
|
||||||
|
|
||||||
|
if(file_exists('import.json'))
|
||||||
|
{
|
||||||
|
if(!file_exists('import.lock'))
|
||||||
|
{
|
||||||
|
$json = json_decode(file_get_contents('import.json'), true);
|
||||||
|
$count = count($json['files']);
|
||||||
|
file_put_contents('import.lock', $count); /* one-process locking */
|
||||||
|
$remoteurl = $json['url'];
|
||||||
|
if (!file_exists('media')) { mkdir('media'); }
|
||||||
|
$time = time();
|
||||||
|
$maxtime = $time + 3; /* max exec time: 3 seconds */
|
||||||
|
while ($time <= $maxtime)
|
||||||
|
{
|
||||||
|
$file = array_shift($json['files']); /* get first element while unstacking */
|
||||||
|
if(!empty($file))
|
||||||
|
{ copy($remoteurl.$file, "media/$file"); file_put_contents('import.json', json_encode($json)); } /* TOCHECK: get_headers() & filesize() when header "content-lenght" */
|
||||||
|
else { unlink('import.json'); } /* first element empty: import finished */
|
||||||
|
$time = time();
|
||||||
|
}
|
||||||
|
$count = count($json['files']);
|
||||||
|
unlink('import.lock');
|
||||||
|
}
|
||||||
|
/* return import information page */ ?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Refresh" content="1">
|
||||||
|
<title>Autoblog media import</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Import running: <?php if(isset($count)) { echo $count; } else { echo file_get_contents('import.lock'); } ?> files remaining.<br>
|
||||||
|
The page should refresh every second. If not, <a href="javascript:window.location.reload()">refresh manually</a>.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<?php exit;}
|
||||||
|
|
||||||
// DISPLAY AND CONTROLLERS
|
// DISPLAY AND CONTROLLERS
|
||||||
|
|
||||||
$vvb = new VroumVroum_Blog;
|
$vvb = new VroumVroum_Blog;
|
||||||
|
|
Loading…
Reference in a new issue