+ {$e('updater.h_check_updates')}
+
+ {$e('updater.current_version')}: $curVersion
+ {$e('updater.last_checked')}: $lastCheckStr
+ $updateStr
+
+
+EOD;
+ }
+
+ function saveSettings(array $params, ?string &$outMessage): bool
+ {
+ return true;
+ }
+
+
+
+ static function preferences(): array
+ {
+ $prefs = Config::requestDomain(self::domain);
+ return $prefs;
+ }
+
+ static function lastVersionInfo(): ?array
+ {
+ $options = array(
+ 'http' => array(
+ 'header' => "Content-type: application/json\r\nUser-Agent: mytinytodo\r\n"
+ )
+ );
+ $context = stream_context_create($options);
+ $json = @file_get_contents("https://api.github.com/repos/maxpozdeev/mytinytodo/releases/latest", false, $context);
+ if ($json === false || $json == '') {
+ return null;
+ }
+ $a = json_decode($json, true) ?? [];
+ $ret = [];
+ if ( isset($a['name']) && isset($a['assets']) &&
+ is_array($a['assets']) && count($a['assets']) > 0 &&
+ ($asset = $a['assets'][0]) && isset($asset['browser_download_url']) )
+ {
+ $ret['version'] = substr($a['name'], 1); //remove first 'v'
+ $ret['download'] = $asset['browser_download_url'];
+ }
+ else {
+ error_log("Unexpected content");
+ }
+ return $ret;
+ }
+
+ static function download(string $url, string $outfile, string &$error = null): bool
+ {
+ $dir = dirname($outfile);
+ if (!is_dir($dir) || !is_writable($dir)) {
+ $error = "myTinyTodo directory is not writable";
+ return false;
+ }
+ $f = @fopen($url, 'r');
+ if ($f === false) {
+ $ea = error_get_last();
+ $error = ($ea && isset($ea['message'])) ? $ea['message'] : "Failed to open stream";
+ return false;
+ }
+ $bytes = @file_put_contents($outfile, $f, LOCK_EX);
+ $ea = error_get_last();
+ fclose($f);
+ if ($bytes === false) {
+ $error = ($ea && isset($ea['message'])) ? $ea['message'] : "Can not save file";
+ return false;
+ }
+ return true;
+ }
+
+ static function extractAndReplace(string $filename, string &$error = null): bool
+ {
+ $dir = MTTPATH;
+ if (!is_dir($dir) || !is_writable($dir)) {
+ $error = "myTinyTodo directory is not writable";
+ return false;
+ }
+
+ $output = null;
+ $retval = null;
+ $command = "tar xzf ". escapeshellarg($filename). " --strip-components 1 -C ". escapeshellarg($dir). " 2>&1";
+ @exec($command, $output, $retval);
+ if ($retval != 0) {
+ $error = "Failed to execute tar command ($retval): ". ($output ? implode("\n", $output) : "no output");
+ error_log($error);
+ return false;
+ }
+
+ // Extensions
+ $dir = MTT_EXT;
+ $filename = $dir . 'extensions.tar.gz';
+ if (file_exists($filename)) {
+ if (!is_writable($dir)) {
+ $error = "Extensions directory is not writable";
+ return false;
+ }
+ $command = "tar xzf ". escapeshellarg($filename). " -C ". escapeshellarg($dir). " 2>&1";
+ @exec($command, $output, $retval);
+ if ($retval != 0) {
+ $error = "Extensions: failed to execute tar command ($retval): ". ($output ? implode("\n", $output) : "no output");
+ error_log($error);
+ return false;
+ }
+ unlink($filename);
+ }
+
+ return true;
+ }
+
+
+}