From 6ba2e6023be40c528e11d859a9a5ab99a1d12022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dvo=C5=99=C3=A1k?= Date: Sun, 15 May 2016 19:24:37 +0200 Subject: [PATCH 1/4] Issues 287 added to the default English language - Modified file functions.inc.php - because if you add new language variable so it is necessary to immediately translate all languages or all files added to the English translation of which is very inconvenient and time consuming. - Function psm_load_lang - loading the default language that I chose English and stored in the $ GLOBALS [ 'sm_lang_default'] for further use. - Function psm_get_lang - edited selection of translation. If there is no translation in the language you chose the user returns to the default language. --- src/includes/functions.inc.php | 58 +++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index f4bbf3d3..c9ff594b 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -40,17 +40,26 @@ function psm_get_lang() { $args = func_get_args(); - if(empty($args)) return $GLOBALS['sm_lang']; + if (empty($args)) return $GLOBALS['sm_lang']; $result = null; + $resultDefault = null; $node = null; + $nodeDefault = null; - if($args) { + if ($args) { $node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $args) . '\']'; + $nodeDefault = '$GLOBALS[\'sm_lang_default\'][\'' . implode('\'][\'', $args) . '\']'; } - eval('if (isset('.$node.')) $result = '.$node.';'); - return $result; + eval('if (isset(' . $node . ')) $result = ' . $node . ';'); + eval('if (isset(' . $nodeDefault . ')) $resultDefault = ' . $nodeDefault . ';'); + + if (empty($result)) { + return $resultDefault; + } else { + return $result; + } } /** @@ -60,12 +69,25 @@ function psm_get_lang() { * @see psm_get_lang() */ function psm_load_lang($lang) { + // if not in the language translation must always be available starting translation - English + $default_lang_file = PSM_PATH_LANG . 'en_US.lang.php'; + + if (file_exists($default_lang_file)) { + require $default_lang_file; + + if (isset($sm_lang)) { + $GLOBALS['sm_lang_default'] = $sm_lang; + unset($sm_lang); + } + } + + // translated language $lang_file = PSM_PATH_LANG . $lang . '.lang.php'; - if(!file_exists($lang_file)) { + if (!file_exists($lang_file)) { // If the file has been removed, we use the english one $en_file = PSM_PATH_LANG . 'en_US.lang.php'; - if(!file_exists($en_file)) { + if (!file_exists($en_file)) { // OK, nothing we can do die('unable to load language file: ' . $lang_file); } @@ -73,7 +95,7 @@ function psm_load_lang($lang) { } require $lang_file; - if(isset($sm_lang['locale'])) { + if (isset($sm_lang['locale'])) { setlocale(LC_TIME, $sm_lang['locale']); } @@ -223,17 +245,17 @@ function psm_add_log($server_id, $type, $message, $user_id = null) { * @param string $latency */ function psm_log_uptime($server_id, $status, $latency) { - global $db; + global $db; - $db->save( - PSM_DB_PREFIX.'servers_uptime', - array( - 'server_id' => $server_id, - 'date' => date('Y-m-d H:i:s'), - 'status' => $status, - 'latency' => $latency, - ) - ); + $db->save( + PSM_DB_PREFIX.'servers_uptime', + array( + 'server_id' => $server_id, + 'date' => date('Y-m-d H:i:s'), + 'status' => $status, + 'latency' => $latency, + ) + ); } /** @@ -584,4 +606,4 @@ function psm_no_cache() { header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); -} +} \ No newline at end of file From 5840c5dca5d25fe7bc44fa23a9b7f271fbcaf9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dvo=C5=99=C3=A1k?= Date: Sun, 15 May 2016 19:32:42 +0200 Subject: [PATCH 2/4] Revert "Issues 287 added to the default English language" This reverts commit 6ba2e6023be40c528e11d859a9a5ab99a1d12022. --- src/includes/functions.inc.php | 58 +++++++++++----------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index c9ff594b..f4bbf3d3 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -40,26 +40,17 @@ function psm_get_lang() { $args = func_get_args(); - if (empty($args)) return $GLOBALS['sm_lang']; + if(empty($args)) return $GLOBALS['sm_lang']; $result = null; - $resultDefault = null; $node = null; - $nodeDefault = null; - if ($args) { + if($args) { $node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $args) . '\']'; - $nodeDefault = '$GLOBALS[\'sm_lang_default\'][\'' . implode('\'][\'', $args) . '\']'; } + eval('if (isset('.$node.')) $result = '.$node.';'); - eval('if (isset(' . $node . ')) $result = ' . $node . ';'); - eval('if (isset(' . $nodeDefault . ')) $resultDefault = ' . $nodeDefault . ';'); - - if (empty($result)) { - return $resultDefault; - } else { - return $result; - } + return $result; } /** @@ -69,25 +60,12 @@ function psm_get_lang() { * @see psm_get_lang() */ function psm_load_lang($lang) { - // if not in the language translation must always be available starting translation - English - $default_lang_file = PSM_PATH_LANG . 'en_US.lang.php'; - - if (file_exists($default_lang_file)) { - require $default_lang_file; - - if (isset($sm_lang)) { - $GLOBALS['sm_lang_default'] = $sm_lang; - unset($sm_lang); - } - } - - // translated language $lang_file = PSM_PATH_LANG . $lang . '.lang.php'; - if (!file_exists($lang_file)) { + if(!file_exists($lang_file)) { // If the file has been removed, we use the english one $en_file = PSM_PATH_LANG . 'en_US.lang.php'; - if (!file_exists($en_file)) { + if(!file_exists($en_file)) { // OK, nothing we can do die('unable to load language file: ' . $lang_file); } @@ -95,7 +73,7 @@ function psm_load_lang($lang) { } require $lang_file; - if (isset($sm_lang['locale'])) { + if(isset($sm_lang['locale'])) { setlocale(LC_TIME, $sm_lang['locale']); } @@ -245,17 +223,17 @@ function psm_add_log($server_id, $type, $message, $user_id = null) { * @param string $latency */ function psm_log_uptime($server_id, $status, $latency) { - global $db; + global $db; - $db->save( - PSM_DB_PREFIX.'servers_uptime', - array( - 'server_id' => $server_id, - 'date' => date('Y-m-d H:i:s'), - 'status' => $status, - 'latency' => $latency, - ) - ); + $db->save( + PSM_DB_PREFIX.'servers_uptime', + array( + 'server_id' => $server_id, + 'date' => date('Y-m-d H:i:s'), + 'status' => $status, + 'latency' => $latency, + ) + ); } /** @@ -606,4 +584,4 @@ function psm_no_cache() { header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); -} \ No newline at end of file +} From 8d5db9edb23385e6b5a1be14426114aea512a1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dvo=C5=99=C3=A1k?= Date: Sun, 15 May 2016 19:36:44 +0200 Subject: [PATCH 3/4] Issue #287 - Added to the default English language - Modified file functions.inc.php - because if you add new language variable so it is necessary to immediately translate all languages or all files added to the English translation of which is very inconvenient and time consuming. - Function psm_load_lang - loading the default language that I chose English and stored in the $ GLOBALS [ 'sm_lang_default'] for further use. - Function psm_get_lang - edited selection of translation. If there is no translation in the language you chose the user returns to the default language. --- src/includes/functions.inc.php | 58 +++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index f4bbf3d3..c9ff594b 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -40,17 +40,26 @@ function psm_get_lang() { $args = func_get_args(); - if(empty($args)) return $GLOBALS['sm_lang']; + if (empty($args)) return $GLOBALS['sm_lang']; $result = null; + $resultDefault = null; $node = null; + $nodeDefault = null; - if($args) { + if ($args) { $node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $args) . '\']'; + $nodeDefault = '$GLOBALS[\'sm_lang_default\'][\'' . implode('\'][\'', $args) . '\']'; } - eval('if (isset('.$node.')) $result = '.$node.';'); - return $result; + eval('if (isset(' . $node . ')) $result = ' . $node . ';'); + eval('if (isset(' . $nodeDefault . ')) $resultDefault = ' . $nodeDefault . ';'); + + if (empty($result)) { + return $resultDefault; + } else { + return $result; + } } /** @@ -60,12 +69,25 @@ function psm_get_lang() { * @see psm_get_lang() */ function psm_load_lang($lang) { + // if not in the language translation must always be available starting translation - English + $default_lang_file = PSM_PATH_LANG . 'en_US.lang.php'; + + if (file_exists($default_lang_file)) { + require $default_lang_file; + + if (isset($sm_lang)) { + $GLOBALS['sm_lang_default'] = $sm_lang; + unset($sm_lang); + } + } + + // translated language $lang_file = PSM_PATH_LANG . $lang . '.lang.php'; - if(!file_exists($lang_file)) { + if (!file_exists($lang_file)) { // If the file has been removed, we use the english one $en_file = PSM_PATH_LANG . 'en_US.lang.php'; - if(!file_exists($en_file)) { + if (!file_exists($en_file)) { // OK, nothing we can do die('unable to load language file: ' . $lang_file); } @@ -73,7 +95,7 @@ function psm_load_lang($lang) { } require $lang_file; - if(isset($sm_lang['locale'])) { + if (isset($sm_lang['locale'])) { setlocale(LC_TIME, $sm_lang['locale']); } @@ -223,17 +245,17 @@ function psm_add_log($server_id, $type, $message, $user_id = null) { * @param string $latency */ function psm_log_uptime($server_id, $status, $latency) { - global $db; + global $db; - $db->save( - PSM_DB_PREFIX.'servers_uptime', - array( - 'server_id' => $server_id, - 'date' => date('Y-m-d H:i:s'), - 'status' => $status, - 'latency' => $latency, - ) - ); + $db->save( + PSM_DB_PREFIX.'servers_uptime', + array( + 'server_id' => $server_id, + 'date' => date('Y-m-d H:i:s'), + 'status' => $status, + 'latency' => $latency, + ) + ); } /** @@ -584,4 +606,4 @@ function psm_no_cache() { header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); -} +} \ No newline at end of file From 1dfa802fb468190476cacbdc0ca09274bad41195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dvo=C5=99=C3=A1k?= Date: Sun, 15 May 2016 19:42:37 +0200 Subject: [PATCH 4/4] Issue #286 Popular Ports - scripts.js - selection and filling port based on a selection from the popular port - update.tpl.html - Added section with a selection of popular ports - ServerController.php - Methods to getLabels added new label - en_US.lang.php + cs_CZ.lang.php - modified the language of the new texts --- src/lang/cs_CZ.lang.php | 3 ++ src/lang/en_US.lang.php | 3 ++ .../Server/Controller/ServerController.php | 4 ++- .../module/server/server/update.tpl.html | 30 +++++++++++++++++-- static/js/scripts.js | 27 +++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/lang/cs_CZ.lang.php b/src/lang/cs_CZ.lang.php index 08be3b13..a1821573 100644 --- a/src/lang/cs_CZ.lang.php +++ b/src/lang/cs_CZ.lang.php @@ -123,6 +123,9 @@ $sm_lang = array( 'timeout' => 'Časový limit', 'timeout_description' => 'Počet vteřin čekání na odpověď serveru.', 'port' => 'Port', + 'custom_port' => 'Uživatelský Port', + 'popular_ports' => 'Populární Porty', + 'please_select' => 'Prosím vyberte', 'type' => 'Typ', 'type_website' => 'Web', 'type_service' => 'Služba', diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index ab050657..2dce3160 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -122,6 +122,9 @@ $sm_lang = array( 'timeout' => 'Timeout', 'timeout_description' => 'Number of seconds to wait for the server to respond.', 'port' => 'Port', + 'custom_port' => 'Custom Port', + 'popular_ports' => 'Popular Ports', + 'please_select' => 'Please select', 'type' => 'Type', 'type_website' => 'Website', 'type_service' => 'Service', diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index cbf50343..9b813135 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -391,10 +391,12 @@ class ServerController extends AbstractServerController { 'label_timeout' => psm_get_lang('servers', 'timeout'), 'label_timeout_description' => psm_get_lang('servers', 'timeout_description'), 'label_port' => psm_get_lang('servers', 'port'), + 'label_custom_port' => psm_get_lang('servers', 'custom_port'), + 'label_please_select' => psm_get_lang('servers', 'please_select'), + 'label_popular_ports' => psm_get_lang('servers', 'popular_ports'), 'label_type' => psm_get_lang('servers', 'type'), 'label_website' => psm_get_lang('servers', 'type_website'), 'label_service' => psm_get_lang('servers', 'type_service'), - 'label_type' => psm_get_lang('servers', 'type'), 'label_pattern' => psm_get_lang('servers', 'pattern'), 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), 'label_last_check' => psm_get_lang('servers', 'last_check'), diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index dd693640..016ec667 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -24,8 +24,34 @@ -
- +
+ +
+ +
+
+
+
diff --git a/static/js/scripts.js b/static/js/scripts.js index f77c5e3f..e1de60d3 100755 --- a/static/js/scripts.js +++ b/static/js/scripts.js @@ -48,6 +48,33 @@ $().ready(function() { psm_flash_message(); psm_tooltips(); + + // popularPorts + // initial + $('.portGroup').hide(); + var portInput = $('#port').val(); + + if (portInput != '') { + var findPopularPorts = $('#popularPorts').find('option[value=' + portInput + ']'); + + if(findPopularPorts.length) { + $(findPopularPorts).attr("selected", "selected"); + } else { + $('#popularPorts').find('option[value=custom]').attr("selected", "selected"); + $('.portGroup').slideDown(); + } + } + + $('#popularPorts').change(function () { + var popularPorts = $(this).val(); + + if (popularPorts == 'custom') { + $('.portGroup').slideDown(); + } else { + $('#port').val(popularPorts); + $('.portGroup').slideUp(); + } + }); }); function psm_xhr(mod, params, method, on_complete, options) {