[add] cache system

[fix] set thumbnail for directory with image from video preview
This commit is contained in:
Knah Tsaeb 2013-08-08 16:15:57 +02:00
parent 438c515076
commit 69b9b640ae
3 changed files with 71 additions and 17 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ tmp
videos
.project
bin/cronTask.sh
option.php
option.php
pagecache

View File

@ -167,6 +167,7 @@ if (!empty($ci['ac']) && $ci['ac'] === 'view' && !empty($listCurrentFile)) {
$fullTitle = $videoInfo['originalTitle'];
$uploadDate = $videoInfo['uploadDate'];
updateFileInfo($videoInfo['hash'], $fullTitle, $uploadDate);
deleteCache($ci['bc'], $ci['file'], $ci['sort']);
} else {
$fullTitle = $videoInfo['title'].' ('.$videoInfo['originalTitle'].')';
}

View File

@ -131,9 +131,6 @@ Options -Indexes';
return $page;
}
function checkSecure() {
}
function logout() {
}
@ -196,9 +193,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 />';
@ -255,7 +252,7 @@ function removeDir($dir, $fullListDir) {
rmdir($GLOBALS['config']['VIDEODIR'].'/'.$path);
unset($fullListDir[$currentDir]);
file_put_contents($GLOBALS['config']['LISTDIR'], "<?php\n\$fullListDir=".var_export($fullListDir, true).";\n?>");
return $parent;
return $parent;
}
}
@ -388,12 +385,6 @@ function getVideoInfo($file, $dir, $fullListFile) {
function editVideoDescription() {
}
function testCache() {
}
function makeCache() {
}
function getThumbnail($path, $value) {
if (file_exists(getcwd().'/'.$value.'/thumb.jpg')) {
return $path.$value.'/thumb.jpg';
@ -407,14 +398,15 @@ function login($ci) {
$_SESSION['log'] = true;
return true;
} else {
$_SESSION['log'] = false;
return false;
}
}
function defineThumb($bc, $file) {
$path = chunk_split($bc, 8, '/');
if (file_exists($GLOBALS['config']['VIDEODIR'].'/'.$path.$file)) {
copy($GLOBALS['config']['VIDEODIR'].'/'.$path.$file, $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb.jpg');
if (file_exists($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.jpg')) {
copy($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.jpg', $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb.jpg');
}
}
@ -502,6 +494,44 @@ function sendVideo($bc, $file) {
exit ;
}
function cache($bc = '', $file = '', $sort = '') {
$cacheFile = md5($bc.$file.$sort);
if (file_exists($GLOBALS['config']['PAGECACHE'].'/'.$cacheFile.'.html')) {
return $cacheFile;
} else {
return false;
}
}
function writeCache($bc = '', $file = '', $sort = '') {
$data = ob_get_clean();
echo $data;
$cacheFile = md5($bc.$file.$sort);
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheFile.'.html', str_replace(array(
"\r\n",
"\r",
"\n",
"\t",
' ',
' ',
' '
), '', $data));
}
function deleteCache($bc = '', $file = '', $sort = '', $parent = false) {
$cacheFile = md5($bc.$file.$sort);
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheFile.'.html')) {
unlink($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/'.$cacheFile.'.html');
}
if ($parent === true) {
$parent = substr($bc, 0, -8);
$cacheParent = md5($parent.$file.$sort);
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/',$GLOBALS['config']['PAGECACHE'].'/'.$cacheParent.'.html')) {
unlink($_SERVER['DOCUMENT_ROOT'].'/',$GLOBALS['config']['PAGECACHE'].'/'.$cacheParent.'.html');
}
}
}
if (!empty($ci['ac']) && $ci['ac'] === 'login' && !empty($ci['op']) && (int)$ci['op'] === 2) {
verifToken($ci['token']);
if (login($ci) === true) {
@ -513,6 +543,7 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
if ($ci['ac'] === 'renDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$renDir = renDir($ci['renDir'], $ci['bc'], $fullListDir);
deleteCache($ci['bc'], $ci['file'], $ci['sort'], true);
$ci['bc'] = $renDir['bc'];
$fullListDir = $renDir['fullListDir'];
}
@ -520,16 +551,19 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
if ($ci['ac'] === 'newDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addDir = addDir($ci['newDir'], $ci['bc'], $fullListDir);
deleteCache($ci['bc'], $ci['file'], $ci['sort'], true);
$fullListDir = $addDir['fullListDir'];
}
if ($ci['ac'] === 'addVideo' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addVideo = addVideo($ci, $fullListFile);
deleteCache($ci['bc'], $ci['file'], $ci['sort']);
}
if ($ci['ac'] === 'addThumbnail' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addThumbnail = addThumbnail($ci['bc']);
deleteCache($ci['bc'], $ci['file'], $ci['sort'], true);
}
if ($ci['ac'] === 'view' && !empty($ci['op']) && (int)$ci['op'] === 4) {
verifToken($ci['token']);
@ -537,6 +571,7 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
die('Tinker say : You can keep your magic, I have laser beams! ');
}
$deleteVideo = deleteVideo($ci['bc'], $ci['file']);
deleteCache($ci['bc'], $ci['file'], $ci['sort']);
}
if ($ci['ac'] === 'view' && !empty($ci['op']) && (int)$ci['op'] === 3) {
verifToken($ci['token']);
@ -544,6 +579,7 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
die('Tinker say : Blinded you, with Science! ');
}
$defineThumb = defineThumb($ci['bc'], $ci['file']);
deleteCache($ci['bc'], '', $ci['sort'], true);
}
if ($ci['ac'] === 'viewQueue') {
verifToken($ci['token']);
@ -557,6 +593,7 @@ if (isset($ci['ac']) && !empty($ci['ac'])) {
if ($_SESSION['log'] !== true) {
die('Tinker say : wonder what.. This does? ');
}
deleteCache($ci['bc'], $ci['file'], $ci['sort'], true);
$ci['bc'] = removeDir($ci['bc'], $fullListDir);
}
}
@ -574,12 +611,27 @@ if (isset($ci['dl']) && !empty($ci['dl'])) {
<body>
<?php
$token = genToken();
if (!isset($page) && empty($page)) {
if ((empty($_SESSION['log']) || $_SESSION['log'] === false) && $ci['ac'] !== 'login') {
$cache = cache($ci['bc'], $ci['file'], $ci['sort']);
}
if (!empty($cache)) {
$page = file_get_contents($GLOBALS['config']['PAGECACHE'].'/'.$cache.'.html');
echo $page;
} elseif (!isset($page) && empty($page)) {
ob_start();
require 'inc/content.php';
} else {
ob_start();
require 'inc/'.$page.'.php';
}
echo '<p id="time">Exec time : '.round((microtime(TRUE) - $startTime), 5).'</p>';
if (empty($cache)) {
if ((empty($_SESSION['log']) || $_SESSION['log'] === false) && $ci['ac'] !== 'login') {
writeCache($ci['bc'], $ci['file'], $ci['sort']);
}
echo '<p id="time">Make in : '.round((microtime(TRUE) - $startTime), 5).'</p>';
} else {
echo '<p id="time">Serve from cache in : '.round((microtime(TRUE) - $startTime), 5).'</p>';
}
?>
</body>
</html>