Implement icons features (rebuild, tool, etc)
This commit is contained in:
140
helper.php
140
helper.php
@@ -4,71 +4,155 @@
|
||||
// //
|
||||
//////////////////////////////////////////
|
||||
|
||||
require("functions.php");
|
||||
require("filetypes.php");
|
||||
|
||||
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/yuba_prefs.php";
|
||||
$p = unserialize(file_get_contents($prefs_file));
|
||||
|
||||
require("functions.php");
|
||||
require("filetypes.php");
|
||||
|
||||
$mode = $argv[1];
|
||||
$fid = $argv[2];
|
||||
$pathname = $argv[3];
|
||||
$bpath = $argv[4];
|
||||
$mytime = $argv[5];
|
||||
|
||||
$file = pathinfo($pathname, PATHINFO_BASENAME);
|
||||
$ext = pathinfo($pathname, PATHINFO_EXTENSION);
|
||||
|
||||
$tfile = "/tmp/Yuba/".$mytime."/".$fid.".png";
|
||||
|
||||
$shellpath = escapeshellarg($pathname);
|
||||
|
||||
$dbp = new PDO("sqlite:".$bpath."/pool.sqlite3");
|
||||
$dbp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$dbp->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
echo "\nBatch (".$mode."): ".basename($pathname);
|
||||
|
||||
switch ($mode) {
|
||||
|
||||
// Icons //////////////////////////////////////////
|
||||
|
||||
case "icons":
|
||||
|
||||
if (!in_array($ext, $p['i_skip']) && @!$dbp->query("SELECT EXISTS(SELECT 1 FROM icons WHERE fid='".$fid."')")->fetch()[0]) {
|
||||
if ($p['icon_tool'] == 0) {
|
||||
$tool = "qltool";
|
||||
} elseif ($p['icon_tool'] == 1) {
|
||||
$tool = "qlmanage";
|
||||
}
|
||||
|
||||
if (in_array($ext, $p['i_skip'])) {
|
||||
// file extension is in the skip list
|
||||
echo " ->i_skip";
|
||||
break;
|
||||
}
|
||||
|
||||
$tfile = "/tmp/Yuba/".$mytime."/".substr($fid,0,3)."/".$file.".png";
|
||||
if (!is_dir(dirname($tfile))) { @mkdir(dirname($tfile)); }
|
||||
// workaround for qlmanage naming convention
|
||||
|
||||
$rowid = @$dbp->query("SELECT rowid FROM icons WHERE fid='".$fid."'")->fetch()['rowid'];
|
||||
// check for existing icon generation attempt
|
||||
|
||||
if (!$rowid) {
|
||||
// no prior attempt
|
||||
|
||||
$stmt = $dbp->prepare("INSERT INTO icons VALUES (:fid, :hash, :created, :relative_path, :tool)");
|
||||
echo " ->generate";
|
||||
|
||||
$cmd = $bin_qltool." di ".$shellpath." ".$p['icon_size']." ".$p['icon_size']." | base64 --decode > ".$tfile;
|
||||
shell_exec($cmd);
|
||||
} elseif ($rowid && $p['icons'] == 2) {
|
||||
// prior attempt but rebuild mode
|
||||
|
||||
$stmt->BindValue(":fid",$fid);
|
||||
if (@filesize($tfile)) {
|
||||
$hash = md5_file($tfile);
|
||||
$stmt->BindValue(":hash",$hash);
|
||||
if ($row = @$dbp->query("SELECT * FROM icons WHERE hash='".$hash."'")->fetchAll()[0]) {
|
||||
$stmt->BindValue(":created",$row['created']);
|
||||
$stmt->BindValue(":relative_path",$row['relative_path']);
|
||||
$stmt->BindValue(":tool",$row['tool']);
|
||||
} else {
|
||||
$dfile = $bpath."/icons/".substr($hash, 0, 2)."/".$hash.".png";
|
||||
if (!is_dir(dirname($dfile))) { @mkdir(dirname($dfile)); }
|
||||
shell_exec("sips -z ".$p['thumb_size']." ".$p['thumb_size']." ".$tfile." --out ".$dfile);
|
||||
$stmt->BindValue(":created",time());
|
||||
$stmt->BindValue(":relative_path",substr($dfile,strlen($bpath)));
|
||||
$stmt->BindValue(":tool","qltool");
|
||||
}
|
||||
}
|
||||
$stmt = $dbp->prepare("UPDATE icons SET fid = :fid, hash = :hash, created = :created, relative_path = :relative_path, tool = :tool WHERE rowid = ".$rowid);
|
||||
echo " ->rebuild";
|
||||
|
||||
$stmt->execute();
|
||||
} else {
|
||||
// prior attempt
|
||||
|
||||
echo " ->skip";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$stmt->BindValue(":fid",$fid);
|
||||
|
||||
if ($tool == "qltool") {
|
||||
|
||||
$cmd = $bin_qltool." di ".$shellpath." ".$p['icon_size']." ".$p['icon_size']." | base64 --decode > ".escapeshellarg($tfile);
|
||||
|
||||
} elseif ($tool == "qlmanage") {
|
||||
|
||||
// > code for custom qlgenerator bindings goes here <
|
||||
|
||||
$cmd = "qlmanage -ti -f ".floor($p['icon_size']/128)." -o ".basename($tfile)." ".$shellpath;
|
||||
|
||||
}
|
||||
|
||||
shell_exec($cmd);
|
||||
|
||||
if (@filesize($tfile)) {
|
||||
|
||||
$hash = md5_file($tfile);
|
||||
$stmt->BindValue(":hash",$hash);
|
||||
|
||||
if ($row = @$dbp->query("SELECT * FROM icons WHERE hash='".$hash."'")->fetchAll()[0]) {
|
||||
// check for another icon with the same hash
|
||||
|
||||
$stmt->BindValue(":created",$row['created']);
|
||||
$stmt->BindValue(":relative_path",$row['relative_path']);
|
||||
$stmt->BindValue(":tool",$row['tool']);
|
||||
|
||||
echo " ->recycle";
|
||||
|
||||
} else {
|
||||
|
||||
$dfile = $bpath."/icons/".substr($hash, 0, 2)."/".$hash.".png";
|
||||
if (!is_dir(dirname($dfile))) { @mkdir(dirname($dfile)); }
|
||||
|
||||
if ($tool == "qltool") {
|
||||
// qltool makes 2x icons for some reason
|
||||
|
||||
echo " ->use";
|
||||
|
||||
//shell_exec("sips -z ".$p['icon_size']." ".$p['icon_size']." ".$tfile." --out ".$dfile);
|
||||
shell_exec($bin_convert." ".escapeshellarg($tfile)." -scale 50% -strip -define png:compression-level=9 ".$dfile);
|
||||
|
||||
} else {
|
||||
|
||||
shell_exec($bin_convert." ".escapeshellarg($tfile)." -strip -define png:compression-level=9 ".$dfile);
|
||||
|
||||
}
|
||||
|
||||
$stmt->BindValue(":created",time());
|
||||
$stmt->BindValue(":relative_path",substr($dfile,strlen($bpath)));
|
||||
$stmt->BindValue(":tool",$tool);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
echo " ->discard";
|
||||
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
break;
|
||||
|
||||
case: "thumbs":
|
||||
case "thumbs":
|
||||
|
||||
// Thumbs //////////////////////////////////////////
|
||||
|
||||
// "bad" filesizes
|
||||
$discard = array( 3953,
|
||||
4977,
|
||||
5019,
|
||||
6059,
|
||||
6616,
|
||||
17393 );
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
echo "\nHelper (".$mode."): ".basename($pathname)."\n";
|
||||
echo "\n";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user