diff --git a/testing/archive/preview.php b/testing/archive/preview.php new file mode 100644 index 00000000..bc701d25 --- /dev/null +++ b/testing/archive/preview.php @@ -0,0 +1,475 @@ + 1920) $previewSize = 640; + setcookie("previewSize", $previewSize, time() + (86400 * 365), "/"); + } + if(!empty($_POST['thumbSize'])) { + $thumbSize = $_POST['thumbSize']; + if ($thumbSize < 32 || $thumbSize > 320) $thumbSize = 96; + setcookie("thumbSize", $thumbSize, time() + (86400 * 365), "/"); + } + if(!empty($_POST['sortOrder'])) { + $sortOrder = $_POST['sortOrder']; + setcookie("sortOrder", $sortOrder, time() + (86400 * 365), "/"); + } + if(!empty($_POST['showTypes'])) { + $showTypes = $_POST['showTypes']; + setcookie("showTypes", $showTypes, time() + (86400 * 365), "/"); + } + if(!empty($_POST['timeFilter'])) { + $timeFilter = $_POST['timeFilter']; + setcookie("timeFilter", $timeFilter, time() + (86400 * 365), "/"); + } + break; + case 'zipSel': + if (!empty($_POST['check_list'])) { + $zipname = getZip($_POST['check_list']); + } + break; + } + } + + function getZip($files) { + $zipname = MEDIA_PATH . '/cam_' . date("Ymd_His") . '.zip'; + writeLog("Making zip $zipname"); + $zipfiles = fopen($zipname.".files", "w"); + foreach ($files as $file) { + $t = getFileType($file); + if ($t == 't') { + $lapses = findLapseFiles($file); + if (!empty($lapses)) { + foreach($lapses as $lapse) { + fprintf($zipfiles, "$lapse\n"); + } + } + } else { + $base = dataFilename($file); + if (file_exists(MEDIA_PATH . "/$base")) { + fprintf($zipfiles, MEDIA_PATH . "/$base\n"); + } + if ($t == 'v' && file_exists(MEDIA_PATH . "/$base.dat")) { + fprintf($zipfiles, MEDIA_PATH . "/$base.dat\n"); + } + } + } + fclose($zipfiles); + file_put_contents("$zipname.count", "0/100"); + exec("./raspizip.sh $zipname $zipname.files > /dev/null &"); + return $zipname; + } + + function startVideoConvert($bFile) { + global $debugString; + $tFiles = findLapseFiles($bFile); + $tmp = BASE_DIR . '/' . MEDIA_PATH . '/' . getFileType($bFile) . getFileIndex($bFile); + if (!file_exists($tmp)) { + mkdir($tmp, 0777, true); + } + $i= 1; + foreach($tFiles as $tFile) { + copy($tFile, $tmp . '/' . sprintf('i_%05d', $i) . '.jpg'); + $i++; + } + $vFile = substr(dataFilename($bFile), 0, -3) . 'mp4'; + $cmd = $_POST['convertCmd']; + $fp = fopen(BASE_DIR . '/' . CONVERT_CMD, 'w'); + fwrite($fp, $cmd); + fclose($fp); + $cmd = "(" . str_replace("i_%05d", "$tmp/i_%05d", $cmd) . ' ' . BASE_DIR . '/' . MEDIA_PATH . "/$vFile ; rm -rf $tmp;) >/dev/null 2>&1 &"; + writeLog("start lapse convert:$cmd"); + system($cmd); + copy(MEDIA_PATH . "/$bFile", MEDIA_PATH . '/' . $vFile . '.v' . getFileIndex($bFile) .THUMBNAIL_EXT); + writeLog("Convert finished"); + } + + + // function to deletes files and folders recursively + // $deleteMainFiles true r false to delete files from the top level folder + // $deleteSubFiles true or false to delete files from subfolders + // Empty subfolders get removed. + // $root true or false. If true (default) then top dir not removed + function maintainFolders($path, $deleteMainFiles, $deleteSubFiles, $root = true) { + $empty=true; + foreach (glob("$path/*") as $file) { + if (is_dir($file)) { + if (!maintainFolders($file, $deleteMainFiles, $deleteSubFiles, false)) $empty=false; + } else { + if (($deleteSubFiles && !$root) || ($deleteMainFiles && $root)) { + unlink($file); + } else { + $empty=false; + } + } + } + return $empty && !$root && rmdir($path); + } + + //function to draw 1 file on the page + function drawFile($f, $ts, $sel) { + $fType = getFileType($f); + $rFile = dataFilename($f); + $fNumber = getFileIndex($f); + $lapseCount = ""; + switch ($fType) { + case 'v': $fIcon = 'video.png'; break; + case 't': + $fIcon = 'timelapse.png'; + $lapseCount = '(' . count(findLapseFiles($f)). ')'; + break; + case 'i': $fIcon = 'image.png'; break; + default : $fIcon = 'image.png'; break; + } + $duration =''; + if (file_exists(MEDIA_PATH . "/$rFile")) { + $fsz = round ((filesize_n(MEDIA_PATH . "/$rFile")) / 1024); + $fModTime = filemtime(MEDIA_PATH . "/$rFile"); + if ($fType == 'v') { + $duration = ($fModTime - filemtime(MEDIA_PATH . "/$f")) . 's'; + } + } else { + $fsz = 0; + $fModTime = filemtime(MEDIA_PATH . "/$f"); + } + $fDate = @date('Y-m-d', $fModTime); + $fTime = @date('H:i:s', $fModTime); + $fWidth = max($ts + 4, 140); + echo "
"; + echo ""; + echo ""; + echo "  $fNumber "; + echo ""; + echo ""; + echo ""; + if ($fsz > 0) echo "$fsz Kb $lapseCount $duration"; else echo 'Busy'; + echo "
$fDate
$fTime
"; + if ($fsz > 0) echo ""; + echo ""; + if ($fsz > 0) echo ""; + echo "
"; + } + + function getThumbnails() { + global $sortOrder; + global $showTypes; + global $timeFilter, $timeFilterMax; + $files = scandir(MEDIA_PATH, $sortOrder - 1); + $thumbnails = array(); + $nowTime = time(); + foreach($files as $file) { + if($file != '.' && $file != '..' && isThumbnail($file)) { + if ($timeFilter == 1) { + $include = true; + } else { + $timeD = $nowTime - filemtime(MEDIA_PATH . "/$file"); + if ($timeFilter == $timeFilterMax) { + $include = ($timeD >= 86400 * ($timeFilter-1)); + } else { + $include = ($timeD >= (86400 * ($timeFilter - 2))) && ($timeD < (($timeFilter - 1) * 86400)); + } + } + if($include) { + $fType = getFileType($file); + if($showTypes == '1') { + $thumbnails[] = $file; + } + elseif($showTypes == '2' && ($fType == 'i' || $fType == 't')) { + $thumbnails[] = $file; + } + elseif($showTypes == '3' && ($fType == 'v')) { + $thumbnails[] = $file; + } + } + } + } + return $thumbnails; + } + + function diskUsage() { + //Get disk data + $totalSize = round(disk_total_space(BASE_DIR . '/' . MEDIA_PATH) / 1048576); //MB + $currentAvailable = round(disk_free_space(BASE_DIR . '/' . MEDIA_PATH) / 1048576); //MB + $percentUsed = round(($totalSize - $currentAvailable)/$totalSize * 100, 1); + if ($percentUsed > 98) + $colour = 'Red'; + else if ($percentUsed > 90) + $colour = 'Orange'; + else + $colour = 'LightGreen'; + echo '
'; + echo "Used:$percentUsed% Total:$totalSize(MB)"; + echo "
 
"; + echo '
'; + } + + function settingsControls() { + global $previewSize,$thumbSize,$sortOrder, $showTypes; + global $timeFilter, $timeFilterMax; + + echo TXT_PREVIEW . " "; + echo "  " . TXT_THUMB . " "; + echo ' Sort '; + echo ' Types '; + echo ' Filter '; + echo " 
"; + } + + $convertCmd = file_get_contents(BASE_DIR . '/' . CONVERT_CMD); + $thumbnails = getThumbnails(); +?> + + + + + <?php echo CAM_STRING; ?> Download + + + + + + + + + + + + +
 
+ +
+
+ + + + +

+ + + + + + + +

+ "; + if(count($thumbnails) == 0) echo "

No videos/images saved

"; + else { + foreach($thumbnails as $file) { + drawFile($file, $thumbSize, $dSelect); + } + } + if(CONTROLS_POS == 'bottom') {echo "
";settingsControls();} + ?> +
+ + + +
+ + get_zip_progress("' . $zipname . '");'; + } else { + echo ''; + } + ?> + +