diff options
author | nachoparker <nacho@ownyourbits.com> | 2018-04-09 14:13:12 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2018-04-09 20:52:03 +0300 |
commit | 20c0d8098d2ed03ae7e0758c907899c2c7930b6b (patch) | |
tree | 01e4d1cfd6c023ebd472821d20f6cd80fd9789b7 /ncp-web | |
parent | a9b37ab6c6faf6862e61eaf061349eb2aa805fe7 (diff) |
ncp-web: added language dropdown selectorv0.53.27
Diffstat (limited to 'ncp-web')
-rw-r--r-- | ncp-web/L10N.php | 19 | ||||
-rw-r--r-- | ncp-web/index.php | 22 | ||||
-rw-r--r-- | ncp-web/l10n/index.html | 0 | ||||
-rw-r--r-- | ncp-web/l10n/index.php | 1 | ||||
-rw-r--r-- | ncp-web/ncp-launcher.php | 8 | ||||
-rw-r--r-- | ncp-web/ncp-web.cfg | 1 | ||||
-rw-r--r-- | ncp-web/ncp.css | 5 | ||||
-rw-r--r-- | ncp-web/ncp.js | 29 |
8 files changed, 80 insertions, 5 deletions
diff --git a/ncp-web/L10N.php b/ncp-web/L10N.php index 5c0e1881..e00a7909 100644 --- a/ncp-web/L10N.php +++ b/ncp-web/L10N.php @@ -66,6 +66,22 @@ class L10N return ($jsonError == null); } + function save($lang) + { + $cfg = 'ncp-web.cfg'; + $line = file_get_contents( $cfg ); + $str = ''; + if (preg_match('/^LANGUAGE_=\[(([_\w]+,)*[_\w]+)\]$/', $line, $matches)) { + $options = explode(',', $matches[1]); + foreach ($options as $option) { + $opt = trim( $option, "_" ); + $str .= $opt == $lang ? '_' . $opt . '_,' : $opt . ','; + } + } + $str = 'LANGUAGE_=[' . rtrim( $str, ',' ) . ']'; + return file_put_contents( $cfg , $str ); + } + function load_template($module) { if (is_file("./l10n_templates/$module.json")) { @@ -130,7 +146,7 @@ class L10N function load_language_setting($modules_path) { - $webui_config_file = join('/', [rtrim($modules_path, '/'), 'nc-webui.sh']); + $webui_config_file = 'ncp-web.cfg'; $fh = fopen($webui_config_file, 'r') or exit('{ "output": "' . $webui_config_file . ' read error" }'); $lang = "auto"; @@ -148,6 +164,5 @@ class L10N return $lang; } } - } } diff --git a/ncp-web/index.php b/ncp-web/index.php index b3ec641f..861c5c0c 100644 --- a/ncp-web/index.php +++ b/ncp-web/index.php @@ -112,6 +112,23 @@ HTML; <a id=versionlink target="_blank" href="https://github.com/nextcloud/nextcloudpi/blob/master/changelog.md"> <?php echo file_get_contents( "/usr/local/etc/ncp-version" ) ?> </a> +<?php + // language selection drop + if( preg_match('/^(\w+)_=\[(([_\w]+,)*[_\w]+)\]$/', file_get_contents( 'ncp-web.cfg') , $matches) ) + { + $options = explode(",", $matches[2]); + echo "<select id=\"language-selection\" name=\"$matches[1]\">"; + foreach($options as $option) + { + echo "<option value='". trim($option, "_") ."' "; + if( $option[0] == "_" && $option[count($option) - 1] == "_" ) + echo "selected='selected'"; + echo ">". trim($option, "_") ."</option>"; + } + echo "<option value=\"[new]\">new..</option>"; + echo "</select>"; + } +?> </div> <div id="header-right"> <a href="https://ownyourbits.com" id="nextcloud-btn" target="_blank" tabindex="1"> @@ -237,8 +254,9 @@ HTML; <?php include('csrf.php'); - echo '<input type="hidden" id="csrf-token" name="csrf-token" value="' . getCSRFToken() . '"/>'; - echo '<input type="hidden" id="csrf-token-ui" name="csrf-token-ui" value="' . getCSRFToken() . '"/>'; + echo '<input type="hidden" id="csrf-token" name="csrf-token" value="' . getCSRFToken() . '"/>'; + echo '<input type="hidden" id="csrf-token-ui" name="csrf-token-ui" value="' . getCSRFToken() . '"/>'; + echo '<input type="hidden" id="csrf-token-cfg" name="csrf-token-cfg" value="' . getCSRFToken() . '"/>'; ?> <script src="minified.js"></script> <script src="ncp.js"></script> diff --git a/ncp-web/l10n/index.html b/ncp-web/l10n/index.html deleted file mode 100644 index e69de29b..00000000 --- a/ncp-web/l10n/index.html +++ /dev/null diff --git a/ncp-web/l10n/index.php b/ncp-web/l10n/index.php deleted file mode 100644 index a8143662..00000000 --- a/ncp-web/l10n/index.php +++ /dev/null @@ -1 +0,0 @@ -<?php
\ No newline at end of file diff --git a/ncp-web/ncp-launcher.php b/ncp-web/ncp-launcher.php index 3fe1690d..ad1ce062 100644 --- a/ncp-web/ncp-launcher.php +++ b/ncp-web/ncp-launcher.php @@ -202,6 +202,14 @@ else echo ' "output": ' . json_encode( print_sidebar( $l, true ) ) . ' , '; echo ' "ret": "0" }'; } + else if ( $_POST['action'] == "cfg-ui" ) + { + $ret = $l->save( $_POST['value'] ); + $ret = $ret !== FALSE ? 0 : 1; + // return JSON + echo '{ "token": "' . getCSRFToken() . '",'; // Get new token + echo ' "ret": "' . $ret . '" }'; + } } // License diff --git a/ncp-web/ncp-web.cfg b/ncp-web/ncp-web.cfg new file mode 100644 index 00000000..a2b972b1 --- /dev/null +++ b/ncp-web/ncp-web.cfg @@ -0,0 +1 @@ +LANGUAGE_=[_auto_,en,de] diff --git a/ncp-web/ncp.css b/ncp-web/ncp.css index de91fc9c..957a2a5c 100644 --- a/ncp-web/ncp.css +++ b/ncp-web/ncp.css @@ -1317,3 +1317,8 @@ a#versionlink:hover { color: #565656; overflow: auto; } + +#language-selection { + border: none; + color: white; +} diff --git a/ncp-web/ncp.js b/ncp-web/ncp.js index 733753ec..51f139f9 100644 --- a/ncp-web/ncp.js +++ b/ncp-web/ncp.js @@ -371,6 +371,35 @@ $(function() switch_to_section( 'nc-config' ); } ); + // language selection + var langold = $( '#language-selection' ).get( '.value' ); + $( '#language-selection' ).on( 'change', function(e) + { + if( '[new]' == this.get( '.value' ) ) + { + this.set( '.value', langold ); + var url = 'https://github.com/nextcloud/nextcloudpi/wiki/Add-a-new-language-to-ncp-web'; + if ( !window.open( url, '_blank' ) ) // try to open in a new tab first + window.location.href = url; + return; + } + // request + $.request('post', 'ncp-launcher.php', { action:'cfg-ui', + value: this.get( '.value' ), + csrf_token: $( '#csrf-token-cfg' ).get( '.value' ) }).then( + function success( result ) + { + var ret = $.parseJSON( result ); + if ( ret.token ) + $('#csrf-token-cfg').set( { value: ret.token } ); + if ( ret.ret && ret.ret == '0' ) // means that the process was launched + window.location.reload( true ); + else + this.set( '.value', langold ); + } + ).error( errorMsg ) + } ); + // load dashboard info print_dashboard(); } ); |