Files
Yuba/helper.php
2019-06-10 22:04:25 -07:00

65 lines
1.9 KiB
PHP
Executable File

<?
// Yuba batch helper
// //
//////////////////////////////////////////
require("functions.php");
require("filetypes.php");
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/yuba_prefs.php";
$p = unserialize(file_get_contents($prefs_file));
$mode = $argv[1];
$fid = $argv[2];
$pathname = $argv[3];
$bpath = $argv[4];
$mytime = $argv[5];
$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);
switch ($mode) {
case "icons":
if (@!$dbp->query("SELECT EXISTS(SELECT 1 FROM icons WHERE fid='".$fid."')")->fetch()[0]) {
$stmt = $dbp->prepare("INSERT INTO icons VALUES (:fid, :hash, :created, :relative_path, :tool)");
$cmd = $bin_qltool." di ".$shellpath." ".$p['thumb_size']." ".$p['thumb_size']." | base64 --decode | ".$bin_magick." convert - -scale 50% -strip -define png:compression-level=9 ".$tfile;
shell_exec($cmd);
$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)); }
rename($tfile,$dfile);
$stmt->BindValue(":created",time());
$stmt->BindValue(":relative_path",substr($dfile,strlen($bpath)));
$stmt->BindValue(":tool","qltool");
}
}
$stmt->execute();
}
break;
}
echo "\nHelper: ".basename($pathname)."\n";
?>