This commit is contained in:
2018-09-03 03:40:31 -07:00
parent 489ff7cd70
commit bae448657b
5 changed files with 647 additions and 179 deletions

View File

@@ -4,6 +4,9 @@
// Yuba RTC Browser
/////////////////////////////////////////////////////////////////
require "lib/debug.php";
$db_dir = "skim";
$icon_size = 64;
$pad = 28;
@@ -13,8 +16,9 @@ $pad = 28;
<head>
<style>
html { word-wrap: break-word; }
div.container { display: flex; flex-flow: row wrap; justify-content: center; }
div.item { width: <?=$icon_size+$pad;?>px; height: <?=$icon_size+$pad;?>px; padding: <?=$pad;?>px; word-wrap: break-word; }
div.item { width: <?=$icon_size+$pad;?>px; height: <?=$icon_size+$pad;?>px; padding: <?=$pad;?>px; }
div.item { font-family: Helvetica; font-size: 11px; }
div.flexfill { width: <?=$icon_size+($pad*3);?>px; height: 1px; }
img.thumb { padding: 6px; border: 1px solid gainsboro; }
@@ -29,7 +33,41 @@ img { margin-bottom: 8px; }
// Functions
function breadcrumbs() { }
function XML2Array(SimpleXMLElement $parent)
{
$array = array();
foreach ($parent as $name => $element) {
($node = & $array[$name])
&& (1 === count($node) ? $node = array($node) : 1)
&& $node = & $node[];
$node = $element->count() ? XML2Array($element) : trim($element);
}
return $array;
}
function breadcrumbs($zpath, $pathname) {
if (!$pathname) {
return array(array(null,basename($zpath)));
} else {
$pathname_adjusted = str_replace($zpath."/", "", $pathname);
$parts = explode("/", $pathname_adjusted);
$i = count($parts);
while ($i) {
$search_path = $zpath."/".implode("/", array_slice($parts, 0, $i));
if ($i == count($parts)) {
$result[] = array(null, basename($search_path));
} else {
$result[] = array(md5($search_path), basename($search_path));
}
$i--;
}
$result[] = array("",basename($zpath));
return array_reverse($result);
}
}
function shortlabel($filename, $max = 40) {
$suffix = "(...).".pathinfo($filename)['extension'];
@@ -62,76 +100,135 @@ $db_file = $_GET['db'];
$pid = $_GET['pid'];
if ($db_file) {
// View
echo "<a href='?db='>db list</a>";
echo "<hr>";
if (!is_readable($db_file)) { echo "can't read db file"; die; }
echo "<a href='?db='>db list</a>";
echo "<hr>";
$dbo = new PDO("sqlite:".$db_file);
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// Get zpath
$zpath = $dbo->query("SELECT zpath FROM _skim")->fetch()['zpath'];
// Check for initial view
if (!$pid) {
$array = $dbo->query("SELECT children FROM family WHERE (rowid=2)")->fetch()['children'];
$pid = $dbo->query("SELECT pid FROM family WHERE (rowid=2)")->fetch()['pid'];
$view = $dbo->query("SELECT * FROM _skim")->fetchAll()[0];
// hide long strings
$view['qlmanage'] = "hidden";
$view['disks'] = "hidden";
$view['diskutil'] = "hidden";
} else {
$array = $dbo->query("SELECT children FROM family WHERE (pid='".$pid."')")->fetch()['children'];
$view = $dbo->query("SELECT * FROM files WHERE (pid='".$pid."')")->fetchAll()[0];
}
$children = unserialize($array);
// Breadcrumbs
//echo "<pre>"; print_r($array); echo "</pre>";
$crumb = breadcrumbs($zpath,$view['Pathname']);
foreach ($crumb as $myparts) {
if ($myparts[0] === null) {
echo $myparts[1];
} else {
echo "<a href='?db=".$db_file."&pid=".$myparts[0]."'>".$myparts[1]."</a> > ";
}
}
echo "<hr>";
echo "\n<div class='container'>";
dsf
print_r($children);
$array = $dbo->query("SELECT children FROM family WHERE (pid='".$pid."')")->fetch()['children'];
if (count($children) < 1) { echo "dir is empty."; die; }
$children = unserialize($array);
foreach ($children as $item) {
if (!$children) {
echo "<div class='item'>";
/////////////////////////////////////////////////////////////////
// File view
echo "<table><tr>";
$row_a = $dbo->query("SELECT * FROM files WHERE (pid='".$item."')")->fetchAll()[0];
//$row_b = $dbo->query("SELECT * FROM mdls WHERE (pid='".$item."')")->fetchAll()[0];
//$row_c = $dbo->query("SELECT * FROM milk WHERE (pid='".$item."')")->fetchAll()[0];
echo "<td valign='top'>";
$row_a = $dbo->query("SELECT * FROM files WHERE (pid='".$pid."')")->fetchAll()[0];
$row_b = $dbo->query("SELECT * FROM mdls WHERE (pid='".$pid."')")->fetchAll()[0];
if ($row_a['thumb_filename']) {
$aspect = $row_a['thumb_width']/$row_a['thumb_height'];
if ($aspect > 1) {
$width = $icon_size;
$height = $icon_size/$aspect;
} else {
$width = $icon_size*$aspect;
$height = $icon_size;
}
$width = $row_a['thumb_width'];
$height = $row_a['thumb_height'];
$realfile = dirname($db_file).$row_a['thumb_filename'];
$icon = "<img class='thumb' src='".$realfile."' width='".$width."' height='".$height."'>";
$icon = "<img src='".$realfile."' width='".$width."' height='".$height."'>";
} else {
$icon = "<img class='icon' src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
$icon = "<img src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
}
$name = htmlentities(shortlabel($row_a['Filename']));
echo $icon;
echo "</td>";
echo "<td valign='top'>";
debug($row_a,"file");
echo "</td>";
//$row_b['spotlight'] = simplexml_load_string($row_b['spotlight'],LIBXML_NSCLEAN);
echo "<td valign='top'>";
debug($row_b,"mdls");
echo "</td>";
echo "</tr></table>";
/////////////////////////////////////////////////////////////////
if ($row_a['Type'] == "dir") {
// Dir view
} else {
echo "<table><tr><td valign='top'>";
echo "<div class='container'>";
foreach ($children as $item) {
echo "<div class='item'>";
$row_a = $dbo->query("SELECT * FROM files WHERE (pid='".$item."')")->fetchAll()[0];
//$row_b = $dbo->query("SELECT * FROM mdls WHERE (pid='".$item."')")->fetchAll()[0];
//$row_c = $dbo->query("SELECT * FROM milk WHERE (pid='".$item."')")->fetchAll()[0];
if ($row_a['thumb_filename']) {
$aspect = $row_a['thumb_width']/$row_a['thumb_height'];
if ($aspect > 1) {
$width = $icon_size;
$height = $icon_size/$aspect;
} else {
$width = $icon_size*$aspect;
$height = $icon_size;
}
$realfile = dirname($db_file).$row_a['thumb_filename'];
$icon = "<img class='thumb' src='".$realfile."' width='".$width."' height='".$height."'>";
} else {
$icon = "<img class='icon' src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
}
$name = htmlentities(shortlabel($row_a['Filename']));
echo "\n<a href='?db=".$db_file."&pid=".$row_a['pid']."'>".$icon."</a><br>".$name;
} else {
echo $icon."<br>".$name;
echo "</div>";
echo "<br>";
}
echo str_repeat("<div class='flexfill'></div>", 100);
echo "</div>";
echo "<br>";
echo "</td><td valign='top'>";
debug($view,$view['Pathname']);
echo "</td></tr></table>";
}
echo str_repeat("<div class='flexfill'></div>", 100);
echo "\n</div>";
} else {
@@ -139,7 +236,7 @@ if ($db_file) {
// DB List
$bundles = glob("skim/*.bundle");
$bundles = glob($db_dir."/*.bundle");
foreach ($bundles as $bundle) {
echo "<h2>".pathinfo($bundle)['filename']."</h2>";
$dbs = glob($bundle."/*.sqlite3");
@@ -147,9 +244,9 @@ if ($db_file) {
if (!strpos($db_file,"pool")) {
echo "<a href='?db=".$db_file."'>".pathinfo($db_file)['filename']."</a>&nbsp;";
$dbo = new PDO("sqlite:".$db_file);
echo $dbo->query("SELECT type FROM _skim WHERE (rowid=1)")->fetch()['type'].", ";
echo $dbo->query("SELECT passed_total FROM _skim WHERE (rowid=1)")->fetch()['passed_total']." files, ";
echo $dbo->query("SELECT status FROM _skim WHERE (rowid=1)")->fetch()['status'];
echo $dbo->query("SELECT type FROM _skim")->fetch()['type'].", ";
echo $dbo->query("SELECT passed_total FROM _skim")->fetch()['passed_total']." files, ";
echo $dbo->query("SELECT status FROM _skim")->fetch()['status'];
echo "<br>";
}
}