This commit is contained in:
2018-09-05 00:26:26 -07:00
parent bae448657b
commit ca7a7a8a58
4 changed files with 147 additions and 42 deletions

View File

@@ -185,7 +185,7 @@
else
{
$collapse = !($level+1<=1 || $title===true || (is_string($title) && substr($title,0,1)=='*'));
$collapse = false; // hack
$collapse = false;
$result .= "\n<div style='".($collapse?'height:12px':'').";margin-top:2px;margin-bottom:2px;border:1px solid grey;padding:3px;margin-left:15px;background-color:rgb(".(255-($level*10)).",".(255-($level*10)).",".(255-($level*10)).");overflow:hidden;'>\n<div id='tree' style='background-color:silver;font-size:9px;cursor:pointer;float:right;border:1px solid black;width:10px;height:10px;text-align:center;padding:0px;overflow:hidden;' onclick=\"if(this.parentNode.style.height=='12px'){this.parentNode.style.height='';this.innerHTML='-'}else{this.parentNode.style.height='12px';this.innerHTML='+'}\">".($collapse?'+':'-')."</div>";
}
$result .= debug ($value, $title, $plain, $limit, $level+1);

View File

@@ -1,9 +1,10 @@
<?
/////////////////////////////////////////////////////////////////
// Yuba RTC Browser
// Skim RTC Browser
/////////////////////////////////////////////////////////////////
require "togggle.php";
require "lib/debug.php";
$db_dir = "skim";
@@ -16,11 +17,15 @@ $pad = 28;
<head>
<style>
html { word-wrap: break-word; }
html { font-family: Helvetica; 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; }
div.item { font-family: Helvetica; font-size: 11px; }
div.item { font-size: 11px; }
div.flexfill { width: <?=$icon_size+($pad*3);?>px; height: 1px; }
div.size { color: grey; margin-top: 3px; }
img.thumb { padding: 6px; border: 1px solid gainsboro; }
img { margin-bottom: 8px; }
@@ -33,20 +38,50 @@ img { margin-bottom: 8px; }
// Functions
function XML2Array(SimpleXMLElement $parent)
{
$array = array();
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
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;
}
class plistParser extends XMLReader {
public function parseString($string) { $this->XML($string); return $this->process(); }
private function process() {
$this->read();
if($this->nodeType !== XMLReader::DOC_TYPE || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 2); }
if(!$this->next("plist") || $this->nodeType !== XMLReader::ELEMENT || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 3); }
$plist = array(); while($this->read()) { if($this->nodeType == XMLReader::ELEMENT) { $plist[] = $this->parse_node(); } }
if(count($plist) == 1 && $plist[0]) { return $plist[0]; } else { return $plist; }
}
private function parse_node() {
if($this->nodeType !== XMLReader::ELEMENT) return;
switch($this->name) {
case 'data': return base64_decode($this->getNodeText()); break;
case 'real': return floatval($this->getNodeText()); break;
case 'string': return $this->getNodeText(); break;
case 'integer': return intval($this->getNodeText()); break;
case 'date': return $this->getNodeText(); break;
case 'true': return true; break;
case 'false': return false; break;
case 'array': return $this->parse_array(); break;
case 'dict': return $this->parse_dict(); break;
default: throw new Exception(sprintf("Not a valid plist. %s is not a valid type", $this->name), 4);
}
}
private function parse_dict() {
$array = array(); $this->nextOfType(XMLReader::ELEMENT);
do { if($this->nodeType !== XMLReader::ELEMENT || $this->name !== "key") { if(!$this->next("key")) { return $array; } } $key = $this->getNodeText(); $this->nextOfType(XMLReader::ELEMENT); $array[$key] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); }
while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "dict")); return $array;
}
private function parse_array() {
$array = array(); $this->nextOfType(XMLReader::ELEMENT);
do { $array[] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); }
while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "array")); return $array;
}
private function getNodeText() { $string = $this->readString(); $this->nextOfType(XMLReader::END_ELEMENT); return $string; }
private function nextOfType() { $types = func_get_args(); $this->read(); while($this->nodeType && !(in_array($this->nodeType, $types))) { $this->read(); } }
private function isNodeOfTypeName($type, $name) { return $this->nodeType === $type && $this->name === $name; }
}
function breadcrumbs($zpath, $pathname) {
if (!$pathname) {
@@ -98,6 +133,7 @@ function findicon($filename) {
$db_file = $_GET['db'];
$pid = $_GET['pid'];
$search = $_POST['query'];
if ($db_file) {
@@ -107,7 +143,9 @@ if ($db_file) {
if (!is_readable($db_file)) { echo "can't read db file"; die; }
$dbo = new PDO("sqlite:".$db_file);
$dbx = new PDO("sqlite:".dirname($db_file)."/pool.sqlite3");
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$dbx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// Get zpath
@@ -129,22 +167,28 @@ if ($db_file) {
// Breadcrumbs
$crumb = breadcrumbs($zpath,$view['Pathname']);
$xc = "";
foreach ($crumb as $myparts) {
if ($myparts[0] === null) {
echo $myparts[1];
$xc .= $myparts[1];
} else {
echo "<a href='?db=".$db_file."&pid=".$myparts[0]."'>".$myparts[1]."</a> > ";
$xc .= "<a href='?db=".$db_file."&pid=".$myparts[0]."'>".$myparts[1]."</a> > ";
}
}
if (!$search) { echo $xc; echo "<hr>"; }
// Search
echo "<form action='' method='post'><input type='text' name='query' size='50' value='".$search."'><input type='submit' value='query'></form>";
echo "<hr>";
$array = $dbo->query("SELECT children FROM family WHERE (pid='".$pid."')")->fetch()['children'];
$children = unserialize($array);
if (!$children) {
if (!$children && !$search) {
/////////////////////////////////////////////////////////////////
@@ -155,6 +199,8 @@ if ($db_file) {
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];
$row_c = $dbx->query("SELECT * FROM exiftool WHERE (fid='".$row_a['fid']."')")->fetchAll()[0];
$row_d = $dbx->query("SELECT * FROM mediainfo WHERE (fid='".$row_a['fid']."')")->fetchAll()[0];
if ($row_a['thumb_filename']) {
$width = $row_a['thumb_width'];
@@ -162,7 +208,7 @@ if ($db_file) {
$realfile = dirname($db_file).$row_a['thumb_filename'];
$icon = "<img src='".$realfile."' width='".$width."' height='".$height."'>";
} else {
$icon = "<img src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
$icon = "<img src='".findicon($row_a['Filename'])."' width='512' height='512'>";
}
echo $icon;
@@ -170,22 +216,33 @@ if ($db_file) {
echo "</td>";
echo "<td valign='top'>";
debug($row_a,"file");
debug(array($row_a),"file");
if ($row_b) {
$parser = new plistParser();
$row_b['spotlight'] = $parser->parseString($row_b['spotlight']);
debug(array($row_b),"mdls");
}
echo "</td><td valign='top'>";
if ($row_c) {
debug(array(unserialize($row_c['tags'])),"exiftool");
}
if ($row_d) {
debug(array(json_decode(json_encode(simplexml_load_string($row_d['info'])))),"mediainfo");
}
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>";
/////////////////////////////////////////////////////////////////
// Dir view
} else {
} elseif (!$search) {
echo "<table><tr><td valign='top'>";
echo "<div class='container'>";
@@ -193,11 +250,15 @@ if ($db_file) {
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_a = $dbo->query("SELECT * FROM files WHERE (rowid='".$item."')")->fetchAll()[0];
$row_b = $dbo->query("SELECT * FROM mdls WHERE (rowid='".$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) {
@@ -213,9 +274,17 @@ if ($db_file) {
$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>";
echo "\n<a href='?db=".$db_file."&pid=".$row_a['pid']."'>".$icon."</a><br>".$name;
echo "<div class='title'>".htmlentities(shortlabel($row_a['Filename']))."</div>";
if ($row_a['Size']) {
echo "<div class='size'>".human_filesize($row_a['Size'])."</div>";
}
if ($row_a['type'] == "dir" && $row_a['items']) {
echo "<div class='size'>".$row_a['items']." items</div>";
}
echo "</div>";
echo "<br>";
@@ -228,6 +297,24 @@ if ($db_file) {
debug($view,$view['Pathname']);
echo "</td></tr></table>";
} else {
/////////////////////////////////////////////////////////////////
// Search
$result = $dbo->query("SELECT * FROM files WHERE (Filename LIKE '%".$search."%')")->fetchAll();
if (count($result)) {
echo count($result)." results<br>";
foreach ($result as $row) {
$pathbold = str_ireplace($search,"<b>".$search."</b>",$row['Pathname']);
echo "\n<a href='?db=".$db_file."&pid=".$row['pid']."'>".$pathbold."</a><br>";
}
} else {
echo "No results for ".$search;
}
}
} else {
@@ -247,6 +334,8 @@ if ($db_file) {
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'];
$spotlight_status = $dbo->query("SELECT mdutil FROM _skim")->fetch()['mdutil'];
if (strpos($spotlight_status,"disabled")) { echo " (no spotlight)"; }
echo "<br>";
}
}