$string) { if (substr($string, 0, 2) == "a:") { $array[$key] = unserialize($string); } } return $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]; } function human_date($epoch, $short = null) { if ($short) { return date("m/d/Y", $epoch); } else { return date("m/d/Y g:iA", $epoch); } } function dumpme($mixed = null) { ob_start(); var_dump($mixed); $content = ob_get_contents(); ob_end_clean(); return $content; } function hasicon($filename) { $ext = pathinfo($filename)['extension']; $good = "icons/null.png"; foreach (glob("icons/*.png") as $file) { if (pathinfo($file)['filename'] == $ext) { $good = $file; } } return $good; } function makeicon($dbo, $id) { global $db, $view, $sort; $item = $dbo->query("SELECT * FROM files WHERE (id=".$id.")")->fetchAll()[0]; $mdls = $dbo->query("SELECT * FROM mdls WHERE (id=".$id.")")->fetchAll()[0]; if ($view == "list") { $size = 32; $multiplier = 8; } else { $size = 128; $multiplier = 2; } if ($mdls['FSInvisible']) { $diricon = "/icons/directory_invisible.png"; $fileicon = "/icons/null_invisible.png"; } elseif ($mdls['Kind'] == "Alias" || $item['Type'] == "link") { $diricon = "/icons/directory_alias.png"; $fileicon = "/icons/null_alias.png"; } else { $diricon = "/icons/directory.png"; $fileicon = hasicon($item['Filename']); } $out = "\n"; $isdir = false; if ($item['Type'] == "link") { $target_type = $dbo->query("SELECT Type FROM files WHERE (pathname='".$item['RealPath']."')")->fetch()['Type']; } if ($item['Type'] == "dir" || $target_type == "dir") { $out .= ""; } elseif (isset($item['tinfo'])) { list ($twidth, $theight) = unserialize($item['tinfo']); $out .= ""; } else { $out .= ""; } $out .= ""; return $out; } function breadcrumbs($dbo, $pathname) { $zpath = $dbo->query("SELECT zpath FROM _walkwalk")->fetch()['zpath']; $pathname_adjusted = str_replace($zpath."/", "", $pathname); //echo "pathname = ".$pathname."
pathname_adjusted = ".$pathname_adjusted."
zpath = ".$zpath."
"; $parts = explode("/", $pathname_adjusted); $i = count($parts); while ($i) { $search_path = $zpath."/".implode("/", array_slice($parts, 0, $i)); $id = $dbo->query("SELECT id FROM files WHERE (Pathname='".str_replace("'", "''", $search_path)."')")->fetch()['id']; if ($i == count($parts)) { $result[] = array(null, basename($search_path)); } else { $result[] = array($id, basename($search_path)); } $i--; } if ($pathname == $zpath) { return array(array(null,basename($zpath))); } else { $result[] = array("1",basename($zpath)); return array_reverse($result); } } // there is no db, show a list of sqlite files if (!$db) { echo "
"; $files = glob($db_dir."*.sqlite3"); rsort($files); foreach ($files as $file) { $dbo = new PDO("sqlite:".$file); $dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $row = $dbo->query("SELECT * FROM _walkwalk")->fetchAll(); if ($row[0]['type'] == "External disk") { $icon = "icons/firewire.png"; } if ($row[0]['type'] == "Startup disk") { $icon = "icons/internal.png"; } if ($row[0]['type'] == "Disk image") { $icon = "icons/image.png"; } if ($row[0]['type'] == "Folder") { $icon = "icons/directory.png"; } $version = $dbo->query("SELECT version FROM _walkwalk")->fetch()['version']; $base = basename($file,".sqlite3"); echo "\n
"; echo "\n"; $title = substr($base, 20,strlen($base)); $date = substr($base, 0,10); echo "\n".$title." (".$date.")"; if (str_replace(".","",substr($version,0,5)) > 44) { echo "\n".$dbo->query("SELECT items FROM files WHERE (".$method."=1)")->fetch()['items']." items"; } if ($dbo->query("SELECT status FROM _walkwalk")->fetch()['status'] == "aborted") { echo " (Aborted)"; } echo "\n".$version.""; echo "\n"; echo "\n
"; $dbo = null; } } else { $dbo = new PDO("sqlite:".$db_file); $dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $dbo->query("PRAGMA page_size = 8192"); $dbo->query("PRAGMA cache_size = 20000"); $dbo->query("PRAGMA locking_mode = EXCLUSIVE"); $dbo->query("PRAGMA synchronous = NORMAL"); $dbo->query("PRAGMA journal_mode = WAL"); $zpath = $dbo->query("SELECT zpath FROM _walkwalk")->fetch()['zpath']; $myview = $dbo->query("SELECT * FROM files WHERE (".$method."=".$id.")")->fetchAll()[0]; $type = $myview['Type']; echo "
"; echo "  "; $crumb = breadcrumbs($dbo, $myview['Pathname']); foreach ($crumb as $myparts) { if ($myparts[0] === null) { echo $myparts[1]; } else { echo "\n".$myparts[1]." > "; } } echo ""; if ($view == "icon") { echo "icon | list"; } else { echo "icon | list"; } echo " | "; echo ""; echo "
"; echo "
"; echo "
"; $row = $dbo->query("SELECT * FROM _walkwalk")->fetchAll(); if ($row[0]['type'] == "Startup disk") { echo "Finder.php cannot handle \"/\""; die; } if ($type == "dir") { if ($sort == "name") { $sortby = "Filename ASC"; } if ($sort == "size") { $sortby = "Size DESC"; } if ($sort == "modified") { $sortby = "MTime DESC"; } //$build = unserialize($dbo->query("SELECT children FROM patch WHERE (id=".$id.")")->fetch()['children']); //$items = $dbo->query("SELECT * FROM files WHERE id IN (".implode(", ", $build).") ORDER BY ".$sortby)->fetchAll(); //foreach ($dbo->query("SELECT id FROM patch WHERE (parent=".$id.")")->fetchAll() as $array) { $build[] = $array['id']; } //$items = $dbo->query("SELECT * FROM files WHERE id IN (".implode(", ", $build).") ORDER BY ".$sortby)->fetchAll(); $items = $dbo->query("SELECT * FROM files WHERE (parent=".$id.") ORDER BY ".$sortby)->fetchAll(); if ($view == "icon") { foreach ($items as $item) { echo "\n
"; echo makeicon($dbo, $item['id']); echo "\n"; $tags = null; $tags = @unserialize($dbo->query("SELECT UserTags FROM mdls WHERE (id=".$item['id'].")")->fetch()['UserTags']); if ($tags) { foreach ($tags as $tag) { echo "
 
"; } echo "
 
"; } echo $item['Filename']; if ($item['Type'] == "dir" || $item['Type'] == "bundle" ) { echo " (".$item['items']." Items)"; } echo "\n
"; echo "\n".human_date($item['MTime'],1).""; echo "\n".human_filesize($item['Size']).""; echo "\n
"; } } else { ?> query("SELECT * FROM mdls WHERE (".$method."=".$item['id'].")")->fetchAll()[0]; $meta = $dbo->query("SELECT * FROM metadata WHERE (".$method."=".$item['id'].")")->fetchAll()[0]; $etool = null; $minfo = null; $sinfo = @unserialize($mdls['spotlight']); $etool = @unserialize($meta['exiftool']); $minfo = @unserialize($meta['mediainfo']); $build = array(); $build[] = makeicon($dbo, $item['id']); $subbuild = array(); if ($tags) { foreach ($tags as $tag) { $subbuild[] = "
 
"; } $subbuild[] = "
 
"; } $subbuild[] = $item['Filename']; $build[] = implode($subbuild); $build[] = human_filesize($item['Size']); $kind = null; if ($mdls['Kind']) { $kind = $mdls['Kind']; } elseif ($item['gfi_type']) { $kind = $item['gfi_type']; } elseif ($mdls['Kind'] == "Alias") { $kind = "Alias"; } else { $kind = ucfirst($item['Type']); } $build[] = $kind; $build[] = $item['items']; $build[] = @human_date($item['MTime']); $build[] = @human_date($item['gfi_created']); $build[] = @human_date($mdls['DateAdded']); if ($mdls['PixelWidth']) { $build[] = $mdls['PixelWidth']." x ".$mdls['PixelHeight']." pixels"; } elseif ($etool[0]['ImageWidth']) { $build[] = $etool[0]['ImageWidth']." x ".$etool[0]['ImageHeight']." pixels"; } elseif ($sinfo['kMDItemPageWidth']) { $build[] = round($sinfo['kMDItemPageWidth'],2)." x ".round($sinfo['kMDItemPageHeight'], 2)." points"; } else { $build[] = ""; } $duration = null; if ($meta['duration']) { $duration = $meta['duration']; } elseif ($etool[0]['MediaDuration']) { $duration = $etool[0]['MediaDuration']; } $build[] = $duration; $dto = null; if ($etool[0]['DateTimeOriginal']) { $dto = @human_date(strtotime($etool[0]['DateTimeOriginal'])); } $build[] = $dto; $subbuild = array(); if ($minfo) { $subbuild[] = "[M]"; } if ($etool) { $subbuild[] = "[E]"; } $build[] = implode(" ", $subbuild); echo ""; foreach ($build as $piece) { echo ""; } echo ""; } echo "
  Filename Size Kind Items Modified Created Added Dimensions Duration DateTime Metadata
".$piece."
"; } } else { // file view echo "
";
		
		$fdeep = $dbo->query("SELECT * FROM files WHERE (id=".$id.")")->fetchAll()[0];
		$sdeep = $dbo->query("SELECT * FROM mdls WHERE (id=".$id.")")->fetchAll()[0];
		$mdeep = $dbo->query("SELECT * FROM metadata WHERE (id=".$id.")")->fetchAll()[0];
		
		echo "

".$fdeep['Pathname']."


"; echo ""; echo ""; echo "

"; if (isset($fdeep['tinfo'])) { echo "

"; } else { echo "

"; } echo dumpme(array_unserialize($fdeep)); echo "

Spotlight


"; echo dumpme(array_unserialize($sdeep)); echo "

Mediainfo


"; echo dumpme(array_unserialize($mdeep)); echo "
"; } } echo str_repeat("
", 100); echo "
"; if ($type == "dir") { echo "
"; echo count($dbo->query("SELECT * FROM files WHERE (parent=".$id.")")->fetchAll())." Items, "; echo human_filesize($dbo->query("SELECT Size FROM files WHERE (id=".$id.")")->fetch()['Size']); } echo " ~ ".round(microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"],2)." seconds"; $dbo = null; ?>