This commit is contained in:
2018-09-16 15:22:15 -07:00
parent 34de0a92c9
commit 01d7489c05
3 changed files with 502 additions and 112 deletions

View File

@@ -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() {