5.4 use htmlentities with UTF-8 charset by default * see http://php.net/manual/fr/function.htmlentities.php * */ function myHtmlentities($var) { return htmlentities($var, ENT_QUOTES, 'UTF-8'); } $ci = array_merge($_POST, $_GET, $_COOKIE); $ci = array_map('myHtmlentities', $ci); $_SESSION['bc'] = $ci['bc']; if (!file_exists($GLOBALS['config']['CONFIG_FILE']) || strlen(file_get_contents($GLOBALS['config']['CONFIG_FILE'])) == 0) { $page = install($ci); } require $GLOBALS['config']['CONFIG_FILE']; require $GLOBALS['config']['LISTDIR']; require $GLOBALS['config']['LISTFILE']; function install($ci) { if (!is_dir($GLOBALS['config']['DATADIR']) && !mkdir($GLOBALS['config']['DATADIR'], 0755)) { die('Error on create dir "DATADIR".'); } if (!is_dir($GLOBALS['config']['VIDEODIR']) && !mkdir($GLOBALS['config']['VIDEODIR'], 0755)) { die('Error on create dir "VIDEODIR".'); } if (!is_dir($GLOBALS['config']['PAGECACHE']) && !mkdir($GLOBALS['config']['PAGECACHE'], 0755)) { die('Error on create dir "PAGECACHE".'); } if (!is_dir($GLOBALS['config']['TMPDIR']) && !mkdir($GLOBALS['config']['TMPDIR'], 0755)) { die('Error on create dir "TMPDIR".'); } if (!copy('inc/.htaccess', $GLOBALS['config']['DATADIR'].'/.htaccess')) { die('Error on create .httaccess in dir "'.$GLOBALS['config']['DATADIR'].'"'); } if (!copy('inc/.htaccess', $GLOBALS['config']['TMPDIR'].'/.htaccess')) { die('Error on create .httaccess in dir "'.$GLOBALS['config']['TMPDIR'].'"'); } if (!is_file($GLOBALS['config']['CONFIG_FILE'])) { touch($GLOBALS['config']['CONFIG_FILE']); } if (!is_file($GLOBALS['config']['IPBANS_FILENAME'])) { touch($GLOBALS['config']['IPBANS_FILENAME']); } if (!is_file($GLOBALS['config']['LISTDIR'])) { touch($GLOBALS['config']['LISTDIR']); } if (!is_file($GLOBALS['config']['LISTFILE'])) { touch($GLOBALS['config']['LISTFILE']); } $page = 'install'; if ($ci['install'] == 'install') { verifToken($ci['token']); $GLOBALS['loginName']['salt'] = hash('sha256', uniqid(rand(), true).'_'.mt_rand()); $GLOBALS['loginName']['loginName'] = hash('sha256', $ci['loginName'].$GLOBALS['loginName']['salt']); $GLOBALS['loginName']['password'] = hash('sha256', $ci['loginPass'].$GLOBALS['loginName']['salt']); $data = ' '; $videoDirHtaccess = ' AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm ForceType application/octet-stream Header set Content-Disposition attachment XSendFile on Options -Indexes'; file_put_contents($GLOBALS['config']['VIDEODIR'].'/.htaccess', $videoDirHtaccess); file_put_contents($GLOBALS['config']['CONFIG_FILE'], $data); $page = 'content'; } return $page; } function logout() { session_unset(); } // In a string, converts urls to clickable links. // src = https://github.com/sebsauvage/Shaarli/blob/master/index.php function text2clickable($url) { return preg_replace('!(((?:https?|ftp|file)://|apt:|magnet:)\S+[[:alnum:]]/?)!si', '$1', $url); } function getCurrentDir($bc) { $currentDir = end(str_split($bc, 8)); return $currentDir; } function genToken() { $token = sha1(uniqid(rand(), true).'_'.mt_rand()); $_SESSION['token'] = $token; $_SESSION['tokenTime'] = time(); return $token; } function verifToken($token) { if ($token !== $_SESSION['token'] || $_SESSION['tokenTime'] <= time() - 24000) { ban(); die('Tinker say : I have several theories I would like to put into practice.'); } return true; } function isLog() { if (empty($_SESSION['log']) || $_SESSION['log'] !== true) { ban(); die('Tinker say : Ooh! They never miss!'); } 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); $path = chunk_split($bc, 8, '/'); if (!empty($file['hash'])) { mkdir($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['VIDEODIR'].'/'.$path.$file['hash']); } $fullListDir[$file['hash']] = $file['name']; file_put_contents($GLOBALS['config']['LISTDIR'], ""); 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']); $data = '0 '.$key.' '.$url.' '.$_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['VIDEODIR'].'/'.$path.$file['hash'].'/'."\n"; file_put_contents($GLOBALS['config']['TMPDIR'].'/'.$key.'.hash', $data); } file_put_contents($GLOBALS['config']['LISTFILE'], ""); } function checkIfBan() { require 'cache/logs/banUser.php'; $userIp = $_SERVER['REMOTE_ADDR']; if (isset($banList[$userIp]) && $banList[$userIp]['nbBan'] >= $GLOBALS['config']['maxErrorBeforeBan'] && $banList[$userIp]['lastBan'] + $GLOBALS['config']['banTime'] > time()) { return true; } elseif (isset($banList[$userIp]) && $banList[$userIp]['lastBan'] + $GLOBALS['config']['banTime'] < time()) { unban(); return false; } else { return false; } } function ban() { require $GLOBALS['config']['IPBANS_FILENAME']; $userIp = $_SERVER['REMOTE_ADDR']; if (isset($banList[$userIp])) { $banList[$userIp]['lastBan'] = time(); $banList[$userIp]['nbBan']++; } else { $banList[$userIp]['lastBan'] = time(); $banList[$userIp]['nbBan'] = 1; } file_put_contents($GLOBALS['config']['IPBANS_FILENAME'], ""); } function unBan() { require $GLOBALS['config']['IPBANS_FILENAME']; $userIp = $_SERVER['REMOTE_ADDR']; unset($banList[$userIp]); file_put_contents($GLOBALS['config']['IPBANS_FILENAME'], ""); } function n_print($data, $name = '') { $aBackTrace = debug_backtrace(); echo '

', $name, '

'; echo '
'; echo ' ', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ' '; echo '
',           htmlentities(print_r($data, 1)), '
'; echo '

'; } function addDir($dir, $breadcrumb, $fullListDir) { if (empty($dir)) { return 'error'; } $dirHash = substr(sha1($dir.microtime(true)), 0, 8); $fullListDir[$dirHash] = $dir; $path = chunk_split($breadcrumb, 8, '/'); file_put_contents($GLOBALS['config']['LISTDIR'], ""); if (mkdir($GLOBALS['config']['VIDEODIR'].'/'.$path.'/'.$dirHash)) { return array( 'result' => 'success', 'fullListDir' => $fullListDir ); } else { return 'error'; } } function renDir($dir, $breadcrumb, $fullListDir) { if (empty($dir)) { return; } $currentDir = getCurrentDir($breadcrumb); $dirHash = substr(sha1($dir.microtime(true)), 0, 8); $fullListDir[$dirHash] = $dir; $path = chunk_split($breadcrumb, 8, '/'); if (rename($GLOBALS['config']['VIDEODIR'].'/'.$path, $GLOBALS['config']['VIDEODIR'].'/'.substr($path, 0, -9).'/'.$dirHash)) { unset($fullListDir[$currentDir]); file_put_contents($GLOBALS['config']['LISTDIR'], ""); $breadcrumb = substr($path, 0, -9).$dirHash; return array( 'result' => 'success', 'bc' => str_replace('/', '', $breadcrumb), 'fullListDir' => $fullListDir ); } else { return 'error'; } } function removeDir($dir, $fullListDir) { $path = chunk_split($dir, 8, '/'); if (empty($dir) || !file_exists($GLOBALS['config']['VIDEODIR'].'/'.$path) || !is_dir($GLOBALS['config']['VIDEODIR'].'/'.$path)) { die('Victory is 10% inspiration, 90% decapitation! '); } else { $parent = substr($dir, 0, -8); $currentDir = getCurrentDir($dir); unlink($GLOBALS['config']['VIDEODIR'].'/'.$path.'/thumb.jpg'); rmdir($GLOBALS['config']['VIDEODIR'].'/'.$path); unset($fullListDir[$currentDir]); file_put_contents($GLOBALS['config']['LISTDIR'], ""); return $parent; } } function addVideo($ci, $fullListFile) { $nameHash = substr(sha1($ci['name'].$ci['url']), 0, 10); $url = escapeshellcmd(html_entity_decode($ci['url'])); if (!empty($ci['bc'])) { $path = chunk_split($ci['bc'], 8, '/'); } else { $path = ''; } if (isset($ci['ddl']) && (int)$ci['ddl'] === 1) { $ddl = 1; } else { $ddl = 0; } $data = $ddl.' '.$nameHash.' '.$url.' '.$_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['VIDEODIR'].'/'.$path."\n"; file_put_contents($GLOBALS['config']['TMPDIR'].'/'.$nameHash.'.hash', $data); $fullListFile[$nameHash] = array( 'title' => $ci['name'], 'url' => $ci['url'], 'desc' => $ci['desc'], 'via' => $ci['via'], 'licence' => $ci['licence'] ); file_put_contents($GLOBALS['config']['LISTFILE'], ""); } function redownloadVideo($bc, $file) { $path = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/'); $pathAndFile = $path.$file; rename($pathAndFile.'.hash', $GLOBALS['config']['TMPDIR'].'/'.$file.'.hash'); } function deleteVideo($bc, $file) { $path = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/'); $pathAndFile = $path.$file; if ((file_exists($pathAndFile.'.jpg') || file_exists($pathAndFile.'.webm')) && !is_dir($pathAndFile) && $file === $_SESSION['video']) { $listFile = (glob($path.$_SESSION['video']."*")); foreach ($listFile as $value) { unlink($value); } } else { return 'Error, cannot delete this file.'; } } function cutVideo($bc, $file) { $path = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/'); $pathAndFile = $path.$file; $_SESSION['cutFile'] = $file; $_SESSION['cutPathFile'] = $path; } function pasteVideo($bc) { $finalDest = $GLOBALS['config']['VIDEODIR'].'/'.chunk_split($bc, 8, '/'); $file = $_SESSION['cutFile']; $path = $_SESSION['cutPathFile']; $allFile = glob($path.$file."*"); foreach ($allFile as $value) { $destName = pathinfo($value); rename($value, $finalDest.$destName['basename']); } unset($_SESSION['cutPathFile'], $_SESSION['cutFile']); } function updateFileInfo($hash, $title, $uploadDate) { global $fullListFile; $fullListFile[$hash]['title'] = $title; $fullListFile[$hash]['uploadDateSort'] = $uploadDate; chdir($_SERVER['DOCUMENT_ROOT']); file_put_contents($GLOBALS['config']['LISTFILE'], ""); } function updateFileDesc($hash, $info) { global $fullListFile; $fullListFile[$hash]['title'] = $info['title']; $fullListFile[$hash]['desc'] = $info['desc']; $fullListFile[$hash]['via'] = $info['via']; chdir($_SERVER['DOCUMENT_ROOT']); file_put_contents($GLOBALS['config']['LISTFILE'], ""); return true; } function listCurrentDir($breadcrumb) { chdir($breadcrumb); return glob("*", GLOB_ONLYDIR); } function sortDir($listCurrentDir, $fullListDir) { foreach ($listCurrentDir as $value) { $rows[$value] = $fullListDir[$value]; } asort($rows); return $rows; } function sortFile($listCurrentFile, $fullListFile, $sort = 'name') { foreach ($listCurrentFile as $value) { $hash = str_replace('.webm', '', $value); $rows[$hash] = array( 'uploadDateSort' => $fullListFile[$hash]['uploadDateSort'], 'title' => $fullListFile[$hash]['title'] ); } $tmp = Array(); if ($sort === 'date') { foreach ($rows as &$ma) { $tmp[] = &$ma["uploadDateSort"]; } } else { foreach ($rows as &$ma) { $tmp[] = &$ma["title"]; } } array_multisort($tmp, $rows); return $rows; } function getQueue() { $allHash = glob("tmp/*.hash"); if ($allHash) { return count($allHash); } else { return '0'; } } function makeBreadcrumb($bc, $fullListDir) { $bcToArray = str_split($bc, 8); $nbBc = count($bcToArray); for ($i = 0; $i < $nbBc; $i++) { $hrefBc .= $bcToArray[$i]; $breadcrumb[$hrefBc] = $fullListDir[$bcToArray[$i]]; } return $breadcrumb; } function listVideo($breadcrumb) { return glob("*.webm"); } function makePLaylist($breadcrumb) { $path = chunk_split($breadcrumb, 8, '/'); $allFile = glob($GLOBALS['config']['VIDEODIR'].'/'.$path."*.webm"); $allFile = glob($GLOBALS['config']['VIDEODIR'].'/'.$breadcrumb."/*.webm"); $m3u = ''; foreach ($allFile as $value) { $m3u .= 'http://'.$_SERVER['HTTP_HOST'].'/'.$value."\n"; } header('Content-type: text/plain'); header("Content-Type: application/force-download"); header("Content-Disposition: Attachment; filename=playlist.m3u"); echo $m3u; exit(); } function makeRss($breadcrumb, $fullListFile) { $path = chunk_split($breadcrumb, 8, '/'); $allFile = glob($GLOBALS['config']['VIDEODIR'].'/'.$path."*.webm"); $rss = ' SoViGall Sat, 07 Sep 2002 00:00:01 GMT http://'.$_SERVER['HTTP_HOST'].''; foreach ($allFile as $value) { $oriValues = $value; $hash = substr(str_replace('.webm', '', $oriValues), -10, 10); $rss .= ' '.html_entity_decode($fullListFile[$hash]['title'], ENT_QUOTES, "UTF-8").' '.html_entity_decode($fullListFile[$hash]['desc'], ENT_QUOTES, "UTF-8").' Origin => '.$fullListFile[$hash]['url'].' '.date("D, d M Y H:i:s", strtotime($fullListFile[$hash]['uploadDateSort'])).' http://'.$_SERVER['HTTP_HOST'].'/'.$value.' '; } $rss .= ' '; header('Content-type: application/rss+xml; charset=UTF-8'); echo $rss; exit(); } function updateVideoInfo($dc, $file) { $path = chunk_split($dc, 8, '/'); $file = escapeshellcmd($file); $bc = escapeshellcmd($path); if (!is_file('bin/getInfo.sh')) { return 'You need configure bin/getInfo.sh'; } exec('bash bin/getInfo.sh '.$file.' '.$bc, $result); $jsonFile = json_decode(file_get_contents($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.info.json')); $jsonFile -> duration = $result[0]; $jsonFile -> format = '0 - '.$result[1]; file_put_contents($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.info.json', json_encode($jsonFile)); return true; } function parseVideoDescription($file, $fullInfo = false) { $value = json_decode(file_get_contents($file)); } function getVideoInfo($file, $dir, $fullListFile) { $file = substr($file, 0, 10); $postInfo = $fullListFile[$file]; $path = chunk_split($dir, 8, '/'); $descFile = glob($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'*.json'); $jsonInfo = json_decode(file_get_contents($descFile[0])); $jsonSize = explode(' - ', htmlentities($jsonInfo -> format)); $jsonSize = explode('x', $jsonSize[1]); $size = $jsonSize[0].'x'.$jsonSize[1]; $time = gmdate('H\hi\ms\s', $jsonInfo -> duration); $uploadDate = htmlentities($jsonInfo -> upload_date, ENT_QUOTES, "UTF-8"); if (empty($uploadDate)) { $uploadDate = gmdate("Ymd", filemtime($GLOBALS['config']['VIDEODIR']."/".$path.$file.".webm")); } $info = array( 'hash' => $file, 'title' => $postInfo['title'], 'originalTitle' => htmlentities($jsonInfo -> title, ENT_QUOTES, "UTF-8"), 'url' => $postInfo['url'], 'desc' => $postInfo['desc'], 'originalDesc' => htmlentities($jsonInfo -> description, ENT_QUOTES, "UTF-8"), 'uploadDateSort' => $postInfo['uploadDateSort'], 'uploadDate' => $uploadDate, 'format' => htmlentities($jsonInfo -> format, ENT_QUOTES, "UTF-8"), 'ext' => htmlentities($jsonInfo -> ext, ENT_QUOTES, "UTF-8"), 'duration' => htmlentities($time, ENT_QUOTES, "UTF-8"), 'size' => htmlentities($size, ENT_QUOTES, "UTF-8"), 'via' => $postInfo['via'], 'licence' => $postInfo['licence'] ); return $info; } function getThumbnail($path, $value) { if (file_exists(getcwd().'/'.$value.'/thumb.jpg')) { return $path.$value.'/thumb.jpg'; } else { return; } } function login($ci) { if (hash('sha256', $ci['loginName'].$GLOBALS['loginName']['salt']) === $GLOBALS['loginName']['loginName'] && $GLOBALS['loginName']['password'] === hash('sha256', $ci['loginPass'].$GLOBALS['loginName']['salt'])) { $_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.'.jpg')) { copy($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.jpg', $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb.jpg'); } } function addThumbnail($bc) { 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'; } $permitImage = array( 'image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png' ); if (!in_array($type, $permitImage)) { echo 'This type '.$type.' file is not permit. Convert it and retry.'; } $path = chunk_split($bc, 8, '/'); if (!move_uploaded_file($_FILES['file']['tmp_name'], $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb'.'.tmp')) { echo 'Error on move file to final destination.'; } else { convertToJpeg($path, $type); } } function convertToJpeg($path, $type) { $pathAndNameFile = $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb'.'.tmp'; if ($type == 'image/jpeg') { $image = imagecreatefromjpeg($pathAndNameFile); } if ($type == 'image/png') { $image = imagecreatefrompng($pathAndNameFile); } if ($type == 'image/gif') { $image = imagecreatefromgif($pathAndNameFile); } imagejpeg($image, $GLOBALS['config']['VIDEODIR'].'/'.$path.'thumb.jpg', 100); imagedestroy($image); unlink($pathAndNameFile); } /* * http://www.php.net/manual/en/function.imagecopyresampled.php */ function makeThumb($path, $file) { $filename = $_SERVER['DOCUMENT_ROOT'].'/'.$path.$file.'.jpg'; $width = 260; $height = 200; list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig / $height_orig; if ($width / $height > $ratio_orig) { $width = $height * $ratio_orig; } else { $height = $width / $ratio_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, $_SERVER['DOCUMENT_ROOT'].'/'.$path.$file.'.thumb.jpg', 100); imagedestroy($image_p); return $path.$file.'.thumb.jpg'; } function sendVideo($bc, $file) { global $fullListFile; $path = chunk_split($bc, 8, '/'); $fileName = html_entity_decode($fullListFile[$file]['title']).'.webm'; $fileNameTesrt = 'tttt.webm'; $fileSize = filesize($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.webm'); $pathAndFile = $GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.webm'; if ($GLOBALS['config']['DOWNLOAD_METHOD'] === 'php') { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"$fileNameTesrt\""); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: '.$fileSize); ob_clean(); flush(); readfile($GLOBALS['config']['VIDEODIR'].'/'.$path.$file.'.webm'); } if ($GLOBALS['config']['DOWNLOAD_METHOD'] === 'xsendfile') { header("X-Sendfile: $pathAndFile"); header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="'.$fileName); } 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) { 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'); } } } function clearCache() { $listOfCache = glob($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS['config']['PAGECACHE'].'/*.html'); foreach ($listOfCache as $value) { if (!unlink($value)) { $error = 1; } } if ($error === 1) { return false; } else { return true; } } function humanFilesize($bytes, $decimals = 2) { $sz = 'BKMGTP'; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).@$sz[$factor]; } if (isset($ci['ac']) && !empty($ci['ac']) && $ci['ac'] === 'm3u') { makePLaylist($ci['bc']); } if (isset($ci['ac']) && !empty($ci['ac']) && $ci['ac'] === 'rss') { makeRss($ci['bc'], $fullListFile); } if (!empty($ci['ac']) && $ci['ac'] === 'login' && !empty($ci['op']) && (int)$ci['op'] === 2) { verifToken($ci['token']); if (login($ci) === true) { unset($ci['op'], $ci['ac']); } } 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']; } 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']); unset($ci['ac']); } 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']); if (!isLog()) { 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']); unset($ci['file']); unset($ci['ac']); } if ($ci['ac'] === 'view' && !empty($ci['op']) && (int)$ci['op'] === 3) { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } $defineThumb = defineThumb($ci['bc'], $ci['file']); deleteCache($ci['bc'], '', $ci['sort'], true); } if ($ci['ac'] === 'view' && !empty($ci['op']) && $ci['op'] === 'cutVideo') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } cutVideo($ci['bc'], $ci['file']); } if ($ci['ac'] === 'view' && !empty($ci['op']) && $ci['op'] === 'reDownload') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } reDownloadVideo($ci['bc'], $ci['file']); } if ($ci['ac'] === 'view' && !empty($ci['op']) && $ci['op'] === 'updateInfo') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } $updateInfo = updateVideoInfo($ci['bc'], $ci['file']); if ($updateInfo !== true) { echo '
', $updateInfo, '
'; } } if ($ci['ac'] === 'view' && !empty($ci['op']) && $ci['op'] === 'updateFileDesc') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } $info = array('title' => $ci['name'], 'desc' => $ci['desc'], 'via' => $ci['via']); $updateInfo = updateFileDesc($ci['file'], $info); if ($updateInfo !== true) { echo '
', $updateInfo, '
'; } } if ($ci['ac'] === 'viewQueue' || $ci['ac'] === 'clearCache') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Seek the heat! '); } $page = 'admin'; } if ($ci['ac'] === 'delDir') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : wonder what.. This does? '); } deleteCache($ci['bc'], $ci['file'], $ci['sort'], true); $ci['bc'] = removeDir($ci['bc'], $fullListDir); } } 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); } if (!empty($ci['op']) && $ci['op'] == 'paste') { verifToken($ci['token']); if (!isLog()) { die('Tinker say : Blinded you, with Science! '); } pasteVideo($ci['bc']); } if ($ci['ac'] === 'logout') { logout(); } ?> SoViGall - Personal Video Gallery Make in : '.round((microtime(TRUE) - $startTime), 5).'

'; } else { echo '

Serve from cache in : '.round((microtime(TRUE) - $startTime), 5).'

'; } ?>