[add] import / export folder with video link ( not send any video)

This commit is contained in:
Knah Tsaeb 2013-08-12 14:51:22 +02:00
parent 4cedc1d814
commit b4ea8f917b
3 changed files with 115 additions and 4 deletions

View File

@ -84,6 +84,19 @@ if (!empty($ci['ac']) && $ci['ac'] === 'addThumbnail' && isLog()) {
<input type="submit"/>
</fieldset>
</form>';
}if (!empty($ci['ac']) && $ci['ac'] === 'importDirForm' && isLog()) {
echo '<form action="?" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Add dir</legend>
<label>Directory</label>
<input type="file" name="file" />
<input type="hidden" name="op" value="1"/>
<input type="hidden" name="ac" value="importDir" />
<input type="hidden" name="bc" value="'.$ci['bc'].'" />
<input type="hidden" name="token" value="', $token, '"/>
<input type="submit"/>
</fieldset>
</form>';
}
if (!empty($ci['ac']) && $ci['ac'] === 'view') {
if (!empty($ci['op']) && (int)$ci['op'] === 1) {

View File

@ -6,6 +6,8 @@
<ul class="topMenu">
<li><a href="?ac=viewQueue&amp;token=',$token,'">Download queue</a></li>
<li><a href="?ac=clearCache&amp;token=',$token,'">Clear cache</a></li>
<li><a href="?ac=export&amp;bc=',$ci['bc'],'&amp;token=',$token,'">Export current dir</a></li>
<li><a href="?ac=importDirForm&amp;bc=',$ci['bc'],'&amp;token=',$token,'">Import dir here</a></li>
</ul>
<ul class="topMenu">
<li><a href="?ac=newDir&amp;bc=', $ci['bc'], '">New directory</a></li>

104
index.php
View File

@ -164,6 +164,88 @@ function isLog() {
return true;
}
function exportDir($bc, $fullListDir, $fullListFile) {
$path = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/');
$currentDir = getCurrentDir($bc);
$exportFile = array(
'hash' => $currentDir,
'name' => $fullListDir[$currentDir]
);
$file = glob($path."*.webm");
foreach ($file as $value) {
$hash = str_replace(array(
'.webm',
$path
), '', $value);
$exportFile['listFile'][$hash] = $fullListFile[$hash];
}
$fileSize = mb_strlen(json_encode($exportFile, '8bit'));
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=sovigall_export.json");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: '.$fileSize);
ob_clean();
flush();
echo json_encode($exportFile);
exit();
}
function importDir($bc, $fullListDir, $fullListFile) {
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
echo 'Error on upload file.';
}
if ($_FILES['file']['error'] > 0) {
$msgError = array(
'1' => 'Le fichier excède le poids autorisé par la directive upload_max_filesize de php.ini',
'2' => 'Le fichier excède le poids autorisé par le champ MAX_FILE_SIZE s\'il a été donné',
'3' => 'Thumbnail are partially upload',
'4' => 'Thumbnail are not upload'
);
echo $msgError[$_FILES["file"]["error"]];
}
$tmpName = $_FILES["file"]["tmp_name"];
if ((int) extension_loaded('fileinfo') === 1) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $tmpName);
finfo_close($finfo);
} else {
echo 'Please active fileinfo extension';
}
if ($type === 'application/json') {
echo 'This type '.$type.' file is not permit. Convert it and retry.';
return;
}
$file = json_decode(file_get_contents($tmpName), true);
if (!empty($file -> hash)) {
mkdir($file -> hash);
}
$fullListDir[$file['hash']] = $file['name'];
file_put_contents($GLOBALS['config']['LISTDIR'], "<?php\n\$fullListDir=".var_export($fullListDir, true).";\n?>");
foreach ($file['listFile'] as $key => $value) {
$fullListFile[$key] = array(
'title' => $value['title'],
'url' => $value['url'],
'desc' => $value['desc'],
'via' => $value['via'],
'licence' => $value['licence'],
'uploadDateSort' => $value['uploadDateSort']
);
$url = escapeshellcmd($value['url']);
$path = chunk_split($ci['bc'], 8, '/');
$data = $key.' '.$url.' '.$path."\n";
file_put_contents($GLOBALS['config']['TMPDIR'].'/'.$key.'.hash', $data);
}
file_put_contents($GLOBALS['config']['LISTFILE'], "<?php\n\$fullListFile=".var_export($fullListFile, true).";\n?>");
}
function checkIfBan() {
require 'cache/logs/banUser.php';
$userIp = $_SERVER['REMOTE_ADDR'];
@ -204,9 +286,9 @@ function n_print($data, $name = '') {
<fieldset style="border: 1px solid orange; padding: 5px;color:#1E1915; background-color: #fff;">';
echo '
<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
</legend>';
echo '<pre style="color:#1E1915;">', htmlentities(print_r($data, 1)), '</pre>';
echo '<pre style="color:#1E1915;">', htmlentities(print_r($data, 1)), '</pre>';
echo '
</fieldset>
<br />';
@ -560,8 +642,8 @@ function deleteCache($bc = '', $file = '', $sort = '', $parent = false) {
unlink($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheFile.'.html');
}
if ($parent === true) {
unset ($file);
unset ($sort);
unset($file);
unset($sort);
$cacheParent = md5($bc.$file.$sort);
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheParent.'.html')) {
unlink($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheParent.'.html');
@ -654,6 +736,20 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
if (isset($ci['dl']) && !empty($ci['dl'])) {
sendVideo($ci['bc'], $ci['dl']);
}
if ($ci['ac'] === 'export') {
verifToken($ci['token']);
if (!isLog()) {
die('Tinker say : wonder what.. This does? ');
}
exportDir($ci['bc'], $fullListDir, $fullListFile);
}
if ($ci['ac'] === 'importDir' && $ci['op'] === '1') {
verifToken($ci['token']);
if (!isLog()) {
die('Tinker say : wonder what.. This does? ');
}
importDir($ci['bc'], $fullListDir, $fullListFile);
}
?>
<!doctype html>
<html lang="fr">