diff --git a/plugins/dynamix.plugin.manager/scripts/language b/plugins/dynamix.plugin.manager/scripts/language new file mode 100644 index 000000000..c043a50da --- /dev/null +++ b/plugins/dynamix.plugin.manager/scripts/language @@ -0,0 +1,290 @@ +#!/usr/bin/php -q +&1", 'r')) { + echo "language: downloading: $url ...\r"; + $level = -1; + while (!feof($file)) { + if (preg_match("/\d+%/", fgets($file), $matches)) { + $percentage = substr($matches[0],0,-1); + if ($percentage > $level) { + echo "language: downloading: $url ... $percentage%\r"; + $level = $percentage; + } + } + } + if (($perror = pclose($file)) == 0) { + echo "language: downloading: $url ... done\n"; + return true; + } else { + echo "language: downloading: $url ... failed (".error_desc($perror).")\n"; + $error = "language: $url download failure (".error_desc($perror).")"; + return false; + } + } else { + $error = "language: $url failed to open"; + return false; + } +} + +function language($method, $xml_file, &$error) { + global $docroot,$plugins,$tmp; + + // parse language XML file + $xml = file_exists($xml_file) ? simplexml_load_file($xml_file,NULL,LIBXML_NOCDATA) : false; + if ($xml === false) { + $error = "XML file doesn't exist or xml parse error"; + return false; + } + switch ($method) { + case 'install': + $url = $xml->LanguageURL; + $zip = basename($url); + $local = "$plugins/dynamix/$zip"; + if ($url) { + if (!download($url, $local, $error)) { + @unlink($local); + return false; + } + } else { + $error = "language: missing URL"; + return false; + } + $name = str_replace('.lang.zip','',$zip); + $path = "$docroot/languages/$name"; + exec("mkdir -p $path"); + @unlink("$docroot/webGui/javascript/translate.$name.js"); + foreach (glob("$path/*.dot",GLOB_NOSORT) as $dot) unlink($dot); + exec("unzip -qqLjo -d $path $local"); + return true; + case 'remove': + $url = $xml->LanguageURL; + if ($url) { + $zip = basename($url); + $name = str_replace('.lang.zip','',$zip); + $path = "$docroot/languages/$name"; + exec("rm -rf $path"); + @unlink("$docroot/webGui/javascript/translate.$name.js"); + @unlink("$plugins/dynamix.$name.xml"); + @unlink("$tmp/dynamix.$name.xml"); + @unlink("$plugins/dynamix/$zip"); + return true; + } else { + $error = "language: missing zip file"; + return false; + } + case 'dump': + // dump file: debugging + echo print_r($xml); + return true; + default: + // return single attribute + $error = "attribute $method not found"; + return $xml->$method ?: false; + } +} + +// MAIN - single argument +if ($argc < 2) { + echo $usage; + exit(1); +} + +$docroot = '/usr/local/emhttp'; +$plugins = '/boot/config/plugins'; +$tmp = '/tmp/plugins'; +$method = $argv[1]; + +if ($method == "checkall") { + echo "language: checking all language packs\n"; + foreach (glob("$plugins/dynamix.*.xml", GLOB_NOSORT) as $lang_file) { + if (language('LanguageURL', $lang_file, $error) === false) continue; + $name = str_replace('dynamix.', '', basename($lang_file, '.xml')); + $lang = language('Language', $lang_file, $error) ?: $name; + echo "language: checking $lang language pack ...\n"; + exec(realpath($argv[0])." check $name >/dev/null"); + } + exit(0); +} + +if ($method == "updateall") { + echo "language: updating all language packs\n"; + foreach (glob("$plugins/dynamix.*.xml", GLOB_NOSORT) as $lang_file) { + if (language('LanguageURL', $lang_file, $error) === false) continue; + $version = language('Version', $lang_file, $error); + $name = str_replace('dynamix.', '', basename($lang_file, '.xml')); + $lang = language('Language', $lang_file, $error) ?: $name; + $latest = language('Version', "$tmp/dynamix.$name.xml", $error); + // update only when newer + if (strcmp($latest, $version) > 0) { + echo "language: updating $lang language pack ...\n"; + exec(realpath($argv[0])." update $name >/dev/null"); + } + } + exit(0); +} + +// MAIN - two arguments +if ($argc != 3) { + echo $usage; + exit(1); +} + +if ($method == 'install') { + echo "language: installing language pack\n"; + if (substr($argv[2],0,7)=='http://' || substr($argv[2],0,8)=='https://') { + $langURL = $argv[2]; + echo "language: downloading $langURL\n"; + $xml_file = "$tmp/dynamix.".str_replace('dynamix.', '', basename($langURL)); + if (!download($langURL, $xml_file, $error)) { + echo "language: $error\n"; + @unlink($xml_file); + exit(1); + } + } else { + $xml_file = realpath($argv[2]); + } + if (language('install', $xml_file, $error) === false) { + echo "language: $error\n"; + exit(1); + } + $lang = language('Language', $xml_file, $error) ?: str_replace('dynamix.', '', basename($xml_file, '.xml')); + copy($xml_file, "$plugins/".basename($xml_file)); + unlink($xml_file); + echo "language: $lang language pack installed\n"; + exit(0); +} + +if ($method == 'check') { + $name = str_replace('dynamix.', '', $argv[2]); + echo "language: checking language pack\n"; + $lang_file = "$plugins/dynamix.$name.xml"; + if (!file_exists($lang_file)) { + echo "language: $name language pack not installed\n"; + exit(1); + } + $templateURL = language('TemplateURL', $lang_file, $error); + if ($templateURL === false) { + echo "language: $error\n"; + exit(1); + } + $xml_file = "$tmp/dynamix.$name.xml"; + if (!download($templateURL, $xml_file, $error)) { + echo "language: $error\n"; + @unlink($xml_file); + exit(1); + } + $version = language('Version', $xml_file, $error); + if ($version === false) { + echo "language: $error\n"; + exit(1); + } + echo "$version\n"; + exit(0); +} + +if ($method == 'update') { + $name = str_replace('dynamix.', '', $argv[2]); + echo "language: updating language pack\n"; + $lang_file = "$plugins/dynamix.$name.xml"; + if (!file_exists($lang_file)) { + echo "language: $name language pack not installed\n"; + exit(1); + } + // verify previous check has been done + $xml_file = "$tmp/dynamix.$name.xml"; + if (!file_exists($xml_file)) { + echo "language: update does not exist, perform a check first\n"; + exit (1); + } + $lang = language('Language', $lang_file, $error) ?: $name; + // check for a reinstall of same version + $old_version = language('Version', $lang_file, $error); + $new_version = language('Version', $xml_file, $error); + if ($new_version == $old_version) { + echo "language: $lang language pack not reinstalling same version\n"; + exit(1); + } + // install the updated plugin + if (language('install', $xml_file, $error) === false) { + echo "language: $error\n"; + exit(1); + } + copy($xml_file, $lang_file); + unlink($xml_file); + echo "language: $lang language pack updated\n"; + exit(0); +} + +if ($method == 'remove') { + $name = str_replace('dynamix.', '', $argv[2]); + echo "language: removing language pack\n"; + $lang_file = "$plugins/dynamix.$name.xml"; + if (!file_exists($lang_file)) { + echo "language: $name language pack not installed\n"; + exit(1); + } + $lang = language('Language', $lang_file, $error) ?: $name; + if (language('remove', $lang_file, $error) === false) { + echo "language: $error\n"; + exit(1); + } + echo "language: $lang language pack removed\n"; + exit(0); +} + +// Return attribute +$value = language($method, $argv[2], $error); +if ($value === false) { + echo "language: $error\n"; + exit(1); +} +echo "$value\n"; +exit(0); +?> diff --git a/plugins/dynamix/Language.page b/plugins/dynamix/Language.page index ef5cbfd62..3b0ba61cf 100644 --- a/plugins/dynamix/Language.page +++ b/plugins/dynamix/Language.page @@ -1,7 +1,7 @@ Menu="WebGui" Title="Language" -Icon="language" -Tag="language" +Icon="icon-language" +Tag="icon-language" --- + + + + +
+
_(Use this to install official language packs)_
+_(Installed languages)_: +: + +_(Enter URL of language pack XML file)_ +:   + +
+
+
+
+
+
+
+ + diff --git a/plugins/dynamix/include/FileUpload.php b/plugins/dynamix/include/FileUpload.php index abe64efa5..ae12efa77 100644 --- a/plugins/dynamix/include/FileUpload.php +++ b/plugins/dynamix/include/FileUpload.php @@ -13,13 +13,14 @@