From 01d7489c05c5bdb4fb8db4620c6ad1b93710d86e Mon Sep 17 00:00:00 2001 From: profiteroles Date: Sun, 16 Sep 2018 15:22:15 -0700 Subject: [PATCH] 0.7.9 --- Yuba.php | 267 ++++++++++++++++++++++++++++++++++------------ functions.php | 60 ++++++++++- web/rtc.php | 287 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 502 insertions(+), 112 deletions(-) diff --git a/Yuba.php b/Yuba.php index 953ff09..fe93cd7 100755 --- a/Yuba.php +++ b/Yuba.php @@ -3,7 +3,7 @@ // Yuba // // ////////////////////////////////////////// -$version = "0.7.7"; +$version = "0.7.9"; ini_set('memory_limit', '4096M'); date_default_timezone_set("America/Los_Angeles"); @@ -14,8 +14,8 @@ date_default_timezone_set("America/Los_Angeles"); require("functions.php"); require("filetypes.php"); -$wopt_noprofile = 1; -$wopt_steps = 9; +$wopt_noprofile = 0; +$wopt_steps = 10; $wopt_currstep = 1; $p = unserialize(file_get_contents("prefs.php")); @@ -32,7 +32,7 @@ if (!is_dir($zpath) | !is_dir($bdest)) { echo "Filepath error"; die; } // Check for bundle if ($zpath == "/") { $blabel = "root"; } else { $blabel = preg_replace("/[^A-Za-z0-9\.]/", "_", basename($zpath)); } -if (is_writable($zpath)) { echo "Warning: source is writeable\n"; } +if (is_writable($zpath)) { echo "Warning: source is writeable"; } $bpath = chop($bdest,"/")."/".substr(crc32($zpath),0,3)."_".$blabel.".bundle"; if (!is_dir($bpath)) { mkdir($bpath); } @@ -79,6 +79,7 @@ $bin_qlthumb = __DIR__."/bin/ql-thumbnail"; // Logfile +$messages_log_file = $bpath."/".$stamp."_messages.log"; $error_log_file = $bpath."/".$stamp."_error.log"; error_reporting(E_ALL); ini_set("display_errors", TRUE); @@ -89,21 +90,21 @@ ini_set("error_log", $error_log_file); ////////////////////////////////////////// $banner = "Yuba: ".$zpath." -> ".$bpath; -echo $banner."\n".str_repeat("-", strlen($banner))."\n"; +echo msg($banner."\n".str_repeat("-", strlen($banner))); // Disk info ////////////////////////////////////////// -echo "Gathering system info...\n"; +echo msg("Gathering system info..."); $host = gethostname(); -$disks = shell_exec("diskutil list 2>&1"); +$disks = shell_exec("diskutil list -plist 2>&1"); $df = shell_exec("df 2>&1"); $df_volume = shell_exec("df ".escapeshellarg($zpath)." | tail -n 1 | rev | cut -d' ' -f1 | rev"); $df_device = shell_exec("df ".escapeshellarg($zpath)." | tail -n 1 | cut -d' ' -f1"); $mdutil = shell_exec("mdutil -s ".$df_volume); if (strpos($mdutil,"disabled")) { - echo "Warning: spotlight indexing is disabled\n"; + echo msg("Warning: spotlight indexing is disabled"); $p['spotlight'] = false; } @@ -114,6 +115,13 @@ if (substr($zpath, 0, 9) != "/Volumes/") { $zbase = "/Volumes/".$zparts[2]; } +$hdiutil = shell_exec("hdiutil info -plist 2>&1"); + +///////////////////////////////////////////////////////////////////////////////////////////// +// rewrite below to use diskutil info -plist +// +// +// $diskutil = shell_exec("diskutil info ".$zbase." 2>&1"); $getdetail = array( "Volume Name", "Protocol", @@ -148,6 +156,11 @@ if ($zpath == "/") { } else { $type = "Folder"; } + +// +// +// +///////////////////////////////////////////////////////////////////////////////////////////// if ($wopt_noprofile) { $profile = "disabled"; @@ -160,10 +173,11 @@ $sysvers = shell_exec("sw_vers 2>&1"); // Database ////////////////////////////////////////// -echo "Building database...\n"; +echo msg("Building database..."); $dbo = new PDO("sqlite:".$bpath."/".$stamp.".sqlite3"); $dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $dbo->query("PRAGMA page_size = 4096"); $dbo->query("PRAGMA cache_size = 10000"); @@ -190,6 +204,7 @@ $dbo->exec("CREATE TABLE _skim ( qlmanage TEXT, sysvers TEXT, diskutil TEXT, + hdiutil TEXT, disks TEXT, df TEXT, df_device TEXT, @@ -237,7 +252,7 @@ $dbo->exec("CREATE TABLE files ( contents_filename TEXT )"); -$stmt = $dbo->prepare("INSERT INTO _skim VALUES (:version, :opts, :host, :uid, :zpath, :bpath, :type, :passed_file, :passed_dir, :passed_link, :passed_total, :nodescended, :ignored, :dupes, :details, :qlmanage, :sysvers, :diskutil, :disks, :df, :df_device, :df_volume, :mdutil, :profile, :status)"); +$stmt = $dbo->prepare("INSERT INTO _skim VALUES (:version, :opts, :host, :uid, :zpath, :bpath, :type, :passed_file, :passed_dir, :passed_link, :passed_total, :nodescended, :ignored, :dupes, :details, :qlmanage, :sysvers, :diskutil, :hdiutil, :disks, :df, :df_device, :df_volume, :mdutil, :profile, :status)"); $stmt->BindValue(":version",$version); $stmt->BindValue(":opts",serialize($p)); $stmt->BindValue(":host",$host); @@ -249,6 +264,7 @@ $stmt->BindValue(":details",$dstring); $stmt->BindValue(":qlmanage",$qlmanage); $stmt->BindValue(":sysvers",$sysvers); $stmt->BindValue(":diskutil",$diskutil); +$stmt->BindValue(":hdiutil",$hdiutil); $stmt->BindValue(":disks",$disks); $stmt->BindValue(":df",$df); $stmt->BindValue(":df_device",$df_device); @@ -311,17 +327,17 @@ $files = new RecursiveIteratorIterator( // Tally ////////////////////////////////////////// -echo "Counting files...\n"; +echo msg("Counting files..."); foreach ($files as $null) { } $first_run = 0; if (!$passed_total) { - echo "Nothing was found, exiting"; + echo msg("Nothing was found, exiting"); die; } -echo "Total files: ".$passed_total."\n"; +echo msg("Total files: ".$passed_total.""); // Pool DB ////////////////////////////////////////// @@ -363,7 +379,7 @@ foreach ($files as $splFileInfo) { $pkey = md5($path); if (array_key_exists($key, $family)) { - echo "Duplicate key on ".$pathname."\n"; die; + echo msg("Duplicate key on ".$pathname.""); die; } $family[$key] = array(); @@ -389,6 +405,7 @@ foreach ($files as $splFileInfo) { } */ + //$sty[$i] = "bypass"; $sty[$i] = statToArray(shell_exec("stat -s ".$shellpath." 2>&1")); // Check file can be read @@ -412,12 +429,12 @@ echo ProgressBar::finish(); // Thow permissions error if (count($noread)) { - echo "Current user (".posix_getuid().") does not have read access to the following files:\n"; + echo msg("Current user (".posix_getuid().") does not have read access to the following files:"); foreach ($noread as $file) { echo $file."\n"; } if ($p['readability']) { - echo "Exiting..."; + echo msg("Exiting..."); die; } } @@ -574,15 +591,20 @@ if ($p['contents']) { if (in_array($ext, $c_files)) { if (!is_dir($cpath)) { mkdir($cpath); } if (!file_exists($cfile) && filesize($pathname) < 25000) { + + msg("Zipping ".$pathname); + + $zip = new ZipArchive(); + $zip->open($cfile, ZipArchive::CREATE); + $zip->addfile($pathname,basename($pathname)); + $zip->close(); + $stmt = $dbp->prepare("INSERT INTO contents VALUES (:fid, :created, :relative_path)"); $stmt->BindValue(":fid",$fid); $stmt->BindValue(":created",time()); $stmt->BindValue(":relative_path",substr($cfile, strlen($bpath))); $stmt->execute(); - $zip = new ZipArchive(); - $zip->open($cfile, ZipArchive::CREATE); - $zip->addfile($pathname,basename($pathname)); - $zip->close(); + } } echo ProgressBar::next(true); @@ -689,6 +711,17 @@ if ($p['hash']) { } +// Pool Indices +////////////////////////////////////////// + +// We are done with the Pool DB, make sure there are indices + +$dbp->exec("CREATE INDEX IF NOT EXISTS contents_index ON contents (fid)"); +$dbp->exec("CREATE INDEX IF NOT EXISTS exiftool_index ON exiftool (fid)"); +$dbp->exec("CREATE INDEX IF NOT EXISTS md5_index ON md5 (fid)"); +$dbp->exec("CREATE INDEX IF NOT EXISTS mediainfo_index ON mediainfo (fid)"); +$dbp->exec("CREATE INDEX IF NOT EXISTS thumbs_index ON thumbs (fid)"); + // Spotlight ////////////////////////////////////////// @@ -741,13 +774,18 @@ if ($p['spotlight']) { foreach ($files as $splFileInfo) { $path = $splFileInfo->getPathname(); + msg($path); + $pid = md5($path); $shellpath = escapeshellarg($path); $mdls = shell_exec("mdls -plist - ".$shellpath." 2>&1"); - if (substr_count(@$mdls,"\n") < 2) { continue; } - - $parser = new plistParser(); - $spotlight = $parser->parseString($mdls); + + if (substr_count(@$mdls,"\n") > 1) { + $parser = new plistParser(); + $spotlight = $parser->parseString(utf8_for_xml($mdls)); + } else { + $spotlight = array(); + } $stmt = $dbo->prepare("INSERT INTO mdls VALUES (".implode(",",$ibuild).")"); @@ -868,7 +906,10 @@ foreach ($files as $splFileInfo) { // Items if ($type == "dir" || $type == "bundle" ) { - $items = chop(@shell_exec("find ".$shellpath." \( ! -regex '.*/\..*' \) | wc -l 2>&1"))-1; + // below commented out because it was causing -1 on dirs beginning with a dot + //$items = chop(@shell_exec("find ".$shellpath." \( ! -regex '.*/\..*' \) | wc -l 2>&1"))-1; + // below should be rewritten to use $wopt_ignore files + $items = chop(@shell_exec("find ".$shellpath." \( ! -regex '.*/\.DS_Store' \) | wc -l 2>&1"))-1; $stmt->BindValue(":items",@$items); } @@ -959,11 +1000,11 @@ foreach ($files as $splFileInfo) { $message[] = "ctime"; } - if (count($message)) { echo "\nFILE = ".$filename."; CHANGE = ".implode(", ", $message)."\n"; } + if (count($message)) { echo msg("FILE = ".$filename."; CHANGE = ".implode(", ", $message).""); } } - echo ProgressBar::next($filename); + echo ProgressBar::next($pathname); $j++; } @@ -973,61 +1014,147 @@ echo ProgressBar::finish(); // Milk ////////////////////////////////////////// -// Aggregate values -$sb['a'] = array( "t*Title" => array("e_Title","k_Title","m_Title"), - "t*Dimensions" => array("k_PixelWidth.k_PixelHeight","e_PixelWidth.e_PixelHeight","m_PixelWidth.m_PixelHeight"), - "i*Seconds" => array("k_DurationSeconds","e_Duration","m_Duration"), - "d*DateTime" => array("e_DateTimeOriginal","m_EncodedDate","e_CreateDate","e_MediaCreateDate","k_ContentCreationDate"), - "t*Origin" => array("e_CameraModelName","e_Producer","e_CreatorTool","e_WriterName","e_Software","e_Encoder","m_WritingApplication"), - "t*GPS" => array("e_GPSPosition","k_Latitude.k_Longitude"), - "t*Author" => array("e_Author","e_Artist","e_Creator","e_By-line") - ); +$milk['t*Title'] = ["e^Title","k^Title","m^Track_name"]; +$milk['t*Format'] = ["m^Format","e^Compression","e^MIMEType"]; +$milk['t*Dimensions'] = ["k^PixelWidth.k^PixelHeight","e^PixelWidth.e^PixelHeight","m^SkimDims"]; +$milk['s*Seconds'] = ["k^DurationSeconds","e^Duration","m^Duration"]; +$milk['d*DateTime'] = ["e^DateTimeOriginal","m^EncodedDate","e^CreateDate","e^MediaCreateDate","k^ContentCreationDate"]; +$milk['t*Origin'] = ["e^CameraModelName","e^Producer","e^CreatorTool","e^WriterName","e^Software","e^Encoder","k^Creator"]; +$milk['t*GPS'] = ["k^Latitude.k^Longitude","e^GPSPosition"]; +$milk['t*Author'] = ["e^Author","e^Artist","e^Creator","e^By-line"]; -// Exiftool values -$sb['e'] = array( "i*Orientation", - "t*Compression", - "t*ProfileDescription", - "i*BitDepth", - "t*LensType", - "t*FocalLength", - "t*Aperture", - "t*LightSource", - "t*WhiteBalance" ); +$milk['i*Tracks'] = ["m^SkimTrackCount"]; +$milk['t*Writer'] = ["m^Writing_application.m^Writing_library"]; +$milk['t*Bitrate'] = ["m^Overall_bit_rate"]; -// Mediainfo values -$sb['m'] = array( "t*VideoFormat", - "t*AudioFormat", - "i*Tracks", - "t*Profile", - "t*Bitrate" ); +$milk['i*Orientation'] = ["e^Orientation"]; +$milk['t*Profile'] = ["e^Profile"]; +$milk['i*BitDepth'] = ["e^BitDepth"]; +$milk['t*LensType'] = ["e^LensType"]; +$milk['t*FocalLength'] = ["e^FocalLength"]; +$milk['t*Aperture'] = ["e^Aperture"]; +$milk['t*LightSource'] = ["e^LightSource"]; +$milk['t*WhiteBalance'] = ["e^WhiteBalance"]; + +$delimiter = ","; // Build DB -unset($cbuild, $ibuild); -foreach (array_merge(array_keys($sb['a']),$sb['e'],$sb['m']) as $name) { - $parts = explode("*",$name); - $ibuild[] = ":".$parts[1]; - if ($parts[0] == "t") { - $cbuild[] = $parts[1]." TEXT"; - } else { - $cbuild[] = $parts[1]." INTEGER"; + +$cbuild = $ibuild = array(); +foreach (array_keys($milk) as $name) { + list($kind,$item) = explode("*",$name); + switch ($kind) { + case "t": + case "d": + case "s": + $cbuild[] = $item." TEXT"; + break; + case "i": + $cbuild[] = $item." INTEGER"; + break; } + $ibuild[] = ":".$item; } $dbo->exec("CREATE TABLE milk (".implode(",",$cbuild).")"); -$stmt = $dbo->prepare("INSERT INTO milk VALUES (".implode(",",$ibuild).")"); -$stmt->execute(); +$countrows = @reset($dbo->query("SELECT max(rowid) FROM files")->fetch()); +echo msg("Milking ".$countrows." rows"); +echo ProgressBar::start($countrows, "Milk"); -//$q = $dbo->query("SELECT rowid, * FROM files"); -//while ($row = $q->fetch_assoc()) { -// print_r($row); -// } -//$q->free(); +$loop = $dbo->query("SELECT rowid, * FROM files"); +while ($row_a = $loop->fetch()) { + + $stmt = $dbo->prepare("INSERT INTO milk VALUES (".implode(",",$ibuild).")"); + + $row_b = @$dbo->query("SELECT * FROM mdls WHERE (rowid='".$row_a['rowid']."')")->fetch(); + if (count(@$row_b) > 1) { + $m['k'] = $row_b; + } else { + $m['k'] = null; + } + + if (isset($row_a['has_exif'])) { + $row_c = $dbp->query("SELECT * FROM exiftool WHERE (rowid='".$row_a['has_exif']."')")->fetch(); + $m['e'] = unserialize($row_c['tags']); + } else { + $m['e'] = null; + } + + if (isset($row_a['has_mediainfo'])) { + + $row_d = $dbp->query("SELECT * FROM mediainfo WHERE (rowid='".$row_a['has_mediainfo']."')")->fetch(); + $decoded = @json_decode(json_encode(simplexml_load_string($row_d['info'])),true); + $m['m'] = $decoded['File']['track'][0]; + + //custom values + + $m['m']['SkimTrackCount'] = @count($decoded['File']['track']); + + @foreach ($decoded['File']['track'] as $track) { + if (!@$m['m']['SkimDims'] && @$track['Width'] && @$track['Height']) { + $m['m']['SkimDims'] = sanitize($track['Width'],"i").$delimiter.sanitize($track['Height'],"i"); + } + } + + // do seconds fix here + + } else { + + $m['m'] = null; + + } + + // M*I*L*K baby + foreach ($milk as $value => $weighted) { + + list($type,$name) = explode("*",$value); + $found = 0; + + foreach ($weighted as $dindex) { + + // concatenante 2 values + if (!$found && strpos($dindex, ".")) { + + $parts = explode(".",$dindex); + $out = array(); + foreach ($parts as $part) { + list($kind,$item) = explode("^",$part); + if (@$m[$kind][$item]) { + $out[] = sanitize($m[$kind][$item],$type); + } + } + if (count($out)) { + $stmt->BindValue(":".$name,implode($delimiter,$out)); + $found = 1; + } + + } elseif (!$found) { + + // find a single value + list($kind,$item) = explode("^",$dindex); + if (@$m[$kind][$item]) { + $stmt->BindValue(":".$name,sanitize($m[$kind][$item],$type)); + $found = 1; + } + + } + } + + } + + echo ProgressBar::next(true); + + $stmt->execute(); + + } + +echo ProgressBar::finish(); // Cleanup ////////////////////////////////////////// -echo "\n"; +echo msg(""); if (file_exists($error_log_file)) { echo file_get_contents($error_log_file); } @@ -1037,7 +1164,7 @@ $dbo->exec("UPDATE _skim SET status='completed_in_".$seconds."'"); // rsync if ($p['rsync_dest']) { - echo "\nrsync...\n"; + echo msg("rsync..."); $command = "rsync -avv -e ssh ".$bpath." ".$p['rsync_dest']; $count = trim(shell_exec("find ".escapeshellarg($bpath)." | wc -l")); echo ProgressBar::start($count,$p['rsync_dest']); @@ -1047,7 +1174,7 @@ if ($p['rsync_dest']) { echo ProgressBar::finish(); } -echo "Finished in ".$seconds." seconds\n\n"; +echo msg("Finished in ".$seconds." seconds"); unset($dbo, $dbp, $files, $family, $fx); diff --git a/functions.php b/functions.php index e0b2116..60ac44a 100755 --- a/functions.php +++ b/functions.php @@ -45,13 +45,14 @@ class ProgressBar { self::$total = $total; self::$time_start = time(); self::$message = $message; - return $message."\n".self::display(); + return msg($message).self::display(); } public static function next($message = null) { self::$done++; + if (is_string($message)) { msg($message); } return self::display($message); - } + } public static function finish() { global $wopt_currstep; @@ -76,6 +77,52 @@ function getParents($zpath, $pathname) { } */ +function msg($string) { + global $messages_log_file; + $logstring = "[".date('Y-m-d h:i:s')."] ".$string."\n"; + file_put_contents($messages_log_file, $logstring, FILE_APPEND); + return $string."\n"; + } + +function timeToSeconds($val) { + if (!is_numeric($val) && strpos($val,":") === false) { + $val = str_replace(" s","",$val); + $val = str_replace(" h ",":",$val); + $val = str_replace(" min",":00",$val); + } + if (!is_numeric($val)) { + $sec = 0; + foreach (array_reverse(explode(':', $val)) as $k => $v) $sec += pow(60, $k) * $v; + $val = $sec; + } + return number_format($val,2,".",""); + } + +function sanitize($val,$type) { + switch($type) { + case "t": + return $val; + break; + case "i": + return filter_var($val,FILTER_SANITIZE_NUMBER_FLOAT); + break; + case "s": + return timeToSeconds($val); + break; + case "d": + if ($formatted = @strtotime($val)) { + return $formatted; + } else { + return $val; + } + break; + } + } + +function is_serial($string) { + return (@unserialize($string) !== false || $string == 'b:0;'); + } + function statToArray($stat) { foreach (explode(" ",$stat) as $part) { $value = explode("=",$part); @@ -84,7 +131,6 @@ function statToArray($stat) { return $out; } - function stepString() { global $wopt_steps; global $wopt_currstep; @@ -109,6 +155,14 @@ function human_filesize($bytes, $decimals = 2) { return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor]; } +function ncenter($string, $title = "DropToPTP") { + exec("osascript -e 'display notification \"".$string."\" with title \"".$title."\"'"); + } + +function utf8_for_xml($string) { + return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string); + } + class plistParser extends XMLReader { public function parseString($string) { $this->XML($string); return $this->process(); } private function process() { diff --git a/web/rtc.php b/web/rtc.php index 0d8c4c1..900b132 100644 --- a/web/rtc.php +++ b/web/rtc.php @@ -4,8 +4,10 @@ // Skim RTC Browser ///////////////////////////////////////////////////////////////// +$browser_version = "0.7.9"; + require "togggle.php"; -require "debug.php"; +require "lib/debug.php"; $db_dir = "skim"; $icon_size = 64; @@ -15,6 +17,7 @@ $pad = 28; + + + + @@ -39,12 +76,58 @@ img { margin-bottom: 8px; } // Functions +function get_gps($gps_pos) { + +# convert: +# 40 deg 44' 49.36" N, 73 deg 56' 28.18" W +# to: +# 40.7470444,-073.9411611 + + $parts = explode(" ",str_replace(array("deg ",",","'","\""),"",$gps_pos)); + + $lat_deg = $parts[0]; + $lat_min = $parts[1]; + $lat_sec = $parts[2]; + $lat_dir = $parts[3]; + + $lon_deg = $parts[4]; + $lon_min = $parts[5]; + $lon_sec = $parts[6]; + $lon_dir = $parts[7]; + + if ($lat_dir == "N") { + $lat_sin = "+"; + } else { + $lat_sin = "-"; + } + + if ($lon_dir == "E") { + $lon_sin = "+"; + } else { + $lon_sin = "-"; + } + + $latitiude = $lat_sin.($lat_deg+($lat_min/60)+($lat_sec/3600)); + $longitude = $lon_sin.($lon_deg+($lon_min/60)+($lon_sec/3600)); + + return $latitiude.",".$longitude; + + } + +function is_serial($string) { + return (@unserialize($string) !== false || $string == 'b:0;'); + } + 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 utf8_for_xml($string) { + return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string); + } + class plistParser extends XMLReader { public function parseString($string) { $this->XML($string); return $this->process(); } private function process() { @@ -117,11 +200,7 @@ function shortlabel($filename, $max = 40) { function findicon($filename) { $ext = pathinfo($filename)['extension']; - if (!$ext) { - $good = "icons/directory.png"; - } else { - $good = "icons/null.png"; - } + $good = "icons/null.png"; foreach (glob("icons/*.png") as $file) { if (pathinfo($file)['filename'] == $ext) { $good = $file; @@ -135,6 +214,7 @@ function findicon($filename) { $db_file = $_GET['db']; $pid = $_GET['pid']; $search = $_POST['query']; +$parser = new plistParser(); if ($db_file) { @@ -156,13 +236,37 @@ if ($db_file) { if (!$pid) { $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"; + $view = $dbo->query("SELECT * FROM _skim")->fetch(); + // handle special strings + $view['opts'] = unserialize($view['opts']); + $view['qlmanage'] = "hidden"; //array($view['qlmanage']); + $view['profile'] = "hidden"; //array($view['profile']); + if ($view['details']) { + $view['details'] = unserialize($view['details']); + } + if (substr($view['disks'],0,5) == "parseString(utf8_for_xml($view['disks'])); + $view['disks'] = "hidden"; + } else { + $view['disks'] = "hidden"; + } + if (substr($view['diskutil'],0,5) == "parseString(utf8_for_xml($view['diskutil'])); + } else { + $view['diskutil'] = "hidden"; + } + if ($view['vdisks']) { + $view['vdisks'] = $parser->parseString(utf8_for_xml($view['vdisks'])); + } + if ($view['hdiutil']) { + $view['hdiutil'] = $parser->parseString(utf8_for_xml($view['hdiutil'])); + } } else { - $view = $dbo->query("SELECT * FROM files WHERE (pid='".$pid."')")->fetchAll()[0]; + $view = $dbo->query("SELECT rowid, * FROM files WHERE (pid='".$pid."')")->fetch(); + if (is_serial($view['stat'])) { + $view['stat'] = unserialize($view['stat']); + } + $dirmdls = $dbo->query("SELECT rowid, * FROM mdls WHERE (rowid='".$view['rowid']."')")->fetch(); } // Breadcrumbs @@ -201,11 +305,15 @@ if ($db_file) { echo ""; echo ""; echo "
"; - $row_a = $dbo->query("SELECT rowid, * FROM files WHERE (pid='".$pid."')")->fetchAll()[0]; + $row_a = $dbo->query("SELECT rowid, * FROM files WHERE (pid='".$pid."')")->fetch(); + if (is_serial($row_a['stat'])) { + $row_a['stat'] = unserialize($row_a['stat']); + } if (!strpos($spotlight_status,"disabled")) { - $row_b = $dbo->query("SELECT * FROM mdls WHERE (rowid='".$row_a['rowid']."')")->fetchAll()[0]; + $row_b = $dbo->query("SELECT * FROM mdls WHERE (rowid='".$row_a['rowid']."')")->fetch(); + $row_e = @$dbo->query("SELECT * FROM milk WHERE (rowid='".$row_a['rowid']."')")->fetch(); } @@ -214,18 +322,18 @@ if ($db_file) { // newer version stores rowid rather than 0 or 1 for has_exif etc if (isset($row_a['has_exif'])) { - $row_c = $dbx->query("SELECT * FROM exiftool WHERE (rowid='".$row_a['has_exif']."')")->fetchAll()[0]; + $row_c = $dbx->query("SELECT * FROM exiftool WHERE (rowid='".$row_a['has_exif']."')")->fetch(); } if (isset($row_a['has_mediainfo'])) { - $row_d = $dbx->query("SELECT * FROM mediainfo WHERE (rowid='".$row_a['has_mediainfo']."')")->fetchAll()[0]; + $row_d = $dbx->query("SELECT * FROM mediainfo WHERE (rowid='".$row_a['has_mediainfo']."')")->fetch(); } } else { // fetch exif and mediainfo by slower fid - $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]; + $row_c = $dbx->query("SELECT * FROM exiftool WHERE (fid='".$row_a['fid']."')")->fetch(); + $row_d = $dbx->query("SELECT * FROM mediainfo WHERE (fid='".$row_a['fid']."')")->fetch(); } @@ -233,22 +341,90 @@ if ($db_file) { $width = $row_a['thumb_width']; $height = $row_a['thumb_height']; $realfile = dirname($db_file).$row_a['thumb_filename']; - $icon = ""; + $icon = ""; + } elseif ($row_a['Type'] == "dir") { + $icon = ""; } else { $icon = ""; } + + if ($row_a['contents_filename']) { + $realcfile = dirname($db_file).$row_a['contents_filename']; + $icon = ""; + } echo $icon; + + // debug milk + + if (count(@$row_e) > 1) { + echo "
"; + foreach($row_e as $title => $val) { + if ($title == "GPS" && $val) { + if (strpos($val,"deg") != false) { + $val = get_gps($val); + } + $print = "".$val.""; + } else { + $print = $val; + } + echo "
".$title."".$print."
"; + } + echo "
"; + } + + // debug file times + + $fileinfo['atime (php)'] = date("F jS, Y h:i:s",$row_a['ATime']); + $fileinfo['mtime (php)'] = date("F jS, Y h:i:s",$row_a['MTime']); + $fileinfo['ctime (php)'] = date("F jS, Y h:i:s",$row_a['CTime']); + + if ($row_a['stat']) { + + if (is_array($row_a['stat'])) { + $fileinfo['atime (stat)'] = date("F jS, Y h:i:s",$row_a['stat']['st_atime']); + $fileinfo['mtime (stat)'] = date("F jS, Y h:i:s",$row_a['stat']['st_mtime']); + $fileinfo['ctime (stat)'] = date("F jS, Y h:i:s",$row_a['stat']['st_ctime']); + $fileinfo['btime (stat)'] = date("F jS, Y h:i:s",$row_a['stat']['st_birthtime']); + + } else { + + // parse old version stat + preg_match('/^Access: ([^\r\n]*)/m', $row_a['stat'], $access); + $fileinfo['atime (stat)'] = date("F jS, Y h:i:s",strtotime($access[1])); + preg_match('/^Modify: ([^\r\n]*)/m', $row_a['stat'], $modify); + $fileinfo['mtime (stat)'] = date("F jS, Y h:i:s",strtotime($modify[1])); + preg_match('/^Change: ([^\r\n]*)/m', $row_a['stat'], $change); + $fileinfo['ctime (stat)'] = date("F jS, Y h:i:s",strtotime($change[1])); + + } + } + + if ($row_b['spotlight']) { + $row_b['spotlight'] = $parser->parseString(utf8_for_xml($row_b['spotlight'])); + $fileinfo['added (mdls)'] = date("F jS, Y h:i:s",$row_b['DateAdded']); + $fileinfo['mtime (mdls)'] = date("F jS, Y h:i:s",$row_b['ContentModificationDate']); + $fileinfo['btime (mdls)'] = date("F jS, Y h:i:s",$row_b['ContentCreationDate']); + } + + ksort($fileinfo); + + echo "
"; + + foreach ($fileinfo as $title => $value) { + echo "
".$title."".$value."
"; + } + + echo "
"; + echo "
"; debug(array($row_a),"file"); - if ($row_b) { - $parser = new plistParser(); - $row_b['spotlight'] = $parser->parseString($row_b['spotlight']); + if ($row_b['spotlight']) { debug(array($row_b),"mdls"); } @@ -280,12 +456,18 @@ if ($db_file) { ///////////////////////// - $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]; + $row_a = $dbo->query("SELECT rowid, * FROM files WHERE (rowid='".$item."')")->fetch(); + $row_b = $dbo->query("SELECT rowid, * FROM mdls WHERE (rowid='".$item."')")->fetch(); + //$row_c = $dbo->query("SELECT * FROM milk WHERE (rowid='".$item."')")->fetch(); ///////////////////////// + if ($row_b['FSInvisible']) { + $visibility = "hidden"; + } else { + $visibility = "unhidden"; + } + if ($row_a['thumb_filename']) { $aspect = $row_a['thumb_width']/$row_a['thumb_height']; if ($aspect > 1) { @@ -296,21 +478,34 @@ if ($db_file) { $height = $icon_size; } $realfile = dirname($db_file).$row_a['thumb_filename']; - $icon = ""; + $icon = ""; + } elseif ($row_a['Type'] == "dir") { + $icon = ""; } else { - $icon = ""; + $icon = ""; } - echo "\n".$icon.""; + echo "\n".$icon.""; - echo "
".htmlentities(shortlabel($row_a['Filename']))."
"; + echo "
"; + + if ($row_b['UserTags']) { + foreach (unserialize($row_b['UserTags']) as $tag) { + echo ""; + } + echo " "; + } + + echo htmlentities(shortlabel($row_a['Filename'])); + + echo "
"; if ($row_a['Size']) { echo "
".human_filesize($row_a['Size'])."
"; } if ($row_a['Type'] == "dir" && $row_a['items']) { - echo "
".$row_a['items']." items
"; + echo "
".number_format($row_a['items'])." items
"; } echo ""; @@ -321,7 +516,14 @@ if ($db_file) { echo str_repeat("
", 100); echo ""; echo "
"; + debug($view,$view['Pathname']); + + if ($dirmdls['spotlight']) { + $dirmdls['spotlight'] = $parser->parseString(utf8_for_xml($dirmdls['spotlight'])); + debug(array($dirmdls),"mdls"); + } + echo "
"; } else { @@ -363,18 +565,25 @@ if ($db_file) { if ($dbs[0]) { $dbo = new PDO("sqlite:".$dbs[0]); $type = $dbo->query("SELECT type FROM _skim")->fetch()['type']; - echo ""; + echo ""; } echo "

".pathinfo($bundle)['filename']."

"; foreach ($dbs as $db_file) { $dbo = new PDO("sqlite:".$db_file); - echo "
"; + $info = $dbo->query("SELECT * FROM _skim")->fetch(); + if (strpos($info['status'],"completed") === 0) { + $seconds = str_replace("completed_in_","",$info['status']); + $status = gmdate("H:i:s",$seconds); + echo "
"; + } else { + echo "
"; + } echo "".pathinfo($db_file)['filename']." "; - echo $dbo->query("SELECT version FROM _skim")->fetch()['version'].", "; - 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 $info['version'].", "; + echo number_format($info['passed_total'])." files, "; + if ($info['image_file']) { echo $info['image_file'].", "; } + echo $status; + if (strpos($info['spotlight_status'],"disabled")) { echo " (no spotlight)"; } echo "
"; } echo "
";