From 5c0c04d42c8309392e7a73f6d17d48605f4d05f1 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 25 Sep 2024 11:08:31 +0700 Subject: [PATCH 1/4] fix: Modify stable url for keyboard download to kmp file --- go/.htaccess | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/.htaccess b/go/.htaccess index 56e046cf..9f8e81e2 100644 --- a/go/.htaccess +++ b/go/.htaccess @@ -8,7 +8,8 @@ RedirectMatch "/go/(([1-9][0-9])([.]?)([0-9]))/developer-help-(mobile|packages)( # Download redirects for keyboard permalinks (TODO: these three rules need refresh) # download-kmp -RedirectMatch "/go/keyboard/([^/?]+)/download/kmp$" "/keyboards/download?id=$1&platform=windows&mode=standalone" +# Modified to match download-package below +RewriteRule "^keyboard/([^/]+)/download/kmp$" "package/download.php?type=keyboard&id=$1" [END,QSA] #download-exe RedirectMatch "/go/keyboard/([^/?]+)/download/exe$" "/keyboards/download?id=$1&platform=windows&mode=bundle" From e1842028b8344817463280e557706e4c59e77319 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 22 Nov 2024 19:35:29 +0700 Subject: [PATCH 2/4] feat: show keyboard preview in keyboard details From Chiang Mai Hackathon. --- _includes/2020/KeymanWebHost.php | 23 ++++++ _includes/includes/ui/keyboard-details.php | 93 +++++++++++++++++++--- cdn/dev/keyboard-search/search.css | 33 ++++++++ developer/keymanweb/index.php | 24 ++---- 4 files changed, 145 insertions(+), 28 deletions(-) create mode 100644 _includes/2020/KeymanWebHost.php diff --git a/_includes/2020/KeymanWebHost.php b/_includes/2020/KeymanWebHost.php new file mode 100644 index 00000000..a6441697 --- /dev/null +++ b/_includes/2020/KeymanWebHost.php @@ -0,0 +1,23 @@ +api_keyman_com}/version/web"); + if($json) { + $json = json_decode($json); + } + if($json && property_exists($json, 'version')) { + $build = $json->version; + } else { + // If the get-version API fails, we'll use the latest known stable version + $build = "16.0.145"; + } + + return "{$KeymanHosts->s_keyman_com}/kmw/engine/$build"; + } +} diff --git a/_includes/includes/ui/keyboard-details.php b/_includes/includes/ui/keyboard-details.php index 5d0e35b5..6c780519 100644 --- a/_includes/includes/ui/keyboard-details.php +++ b/_includes/includes/ui/keyboard-details.php @@ -6,7 +6,8 @@ require_once('includes/appstore.php'); use \DateTime; - use \Keyman\Site\Common\KeymanHosts; +use Keyman\Site\com\keyman\KeymanWebHost; +use \Keyman\Site\Common\KeymanHosts; define('GITHUB_ROOT', 'https://github.com/keymanapp/keyboards/tree/master/'); define('DOCUMENTATION_ROOT', KeymanHosts::Instance()->help_keyman_com . '/keyboard/'); @@ -67,7 +68,9 @@ public static function render_keyboard_details($id, $tier = 'stable', $landingPa self::LoadData(); self::WriteTitle(); + self::WriteDescription(); self::WriteDownloadBoxes(); + self::WriteKeymanWebBox(); self::WriteKeyboardDetails(); if(!empty(self::$deprecatedBy)) echo ""; } @@ -123,7 +126,7 @@ protected static function WriteWebBoxes() { global $embed_target; global $KeymanHosts; if (isset(self::$keyboard->platformSupport->desktopWeb) && self::$keyboard->platformSupport->desktopWeb != 'none' && empty(self::$deprecatedBy)) { - if(empty(self::$bcp47)) { + if(empty(self::$bcp47)) { if (isset(self::$keyboard->languages)) { if (is_array(self::$keyboard->languages)) { if (count(self::$keyboard->languages) > 0) { @@ -142,11 +145,10 @@ protected static function WriteWebBoxes() { if (!isset($lang)) $lang = 'en'; $url = "{$KeymanHosts->keymanweb_com}/#$lang,Keyboard_" . self::$keyboard->id; $description = htmlentities(self::$keyboard->name); - return << - Use keyboard online -
Use $description in your web browser. No need to install anything.
- + Full online editor + END; } return FALSE; @@ -369,24 +371,93 @@ protected static function WriteDownloadBoxes() { } if ($embed == 'none') { - $webtext = self::WriteWebBoxes(); - if ($webtext) { - echo $webtext; + if(self::GetWebDeviceFromPageDevice() == null) { + $webtext = self::WriteWebBoxes(); + if ($webtext) { + echo $webtext; + } } - if(empty(self::$deprecatedBy)) { self::WriteQRCode('other'); } } } + protected static function GetWebDeviceFromPageDevice() { + global $pageDevice; + switch($pageDevice) { + case 'Windows': return 'windows'; + case 'mac': return 'macosx'; + case 'Linux': return 'linux'; + } + return null; + } + + protected static function WriteKeymanWebBox() { + global $embed; + + // don't show if we are embedded into a Keyman app + if($embed != 'none') { + return; + } + + // only show if we have a web keyboard and we are not deprecated + if(!isset(self::$keyboard->platformSupport->desktopWeb) || + self::$keyboard->platformSupport->desktopWeb == 'none' || + !empty(self::$deprecatedBy)) { + return; + } + + // only inject on desktop platforms + $webDevice = self::GetWebDeviceFromPageDevice(); + if(!$webDevice) { + return; + } + + $webtext = self::WriteWebBoxes(); + $cdnUrlBase = KeymanWebHost::getKeymanWebUrlBase(); + ?> +

Try this keyboard

+
+ +
+ +
+ + + " . self::$description . "

"; + } + protected static function WriteKeyboardDetails() { global $embed_target, $session_query_q, $KeymanHosts; // this is html, trusted in database ?>

Keyboard Details

-

diff --git a/cdn/dev/keyboard-search/search.css b/cdn/dev/keyboard-search/search.css index 239b69ac..ef2aaad2 100644 --- a/cdn/dev/keyboard-search/search.css +++ b/cdn/dev/keyboard-search/search.css @@ -314,6 +314,39 @@ p#permalink { font-size: 8pt; } +/* Try this keyboard */ + +#try-box { + display: none; + margin: 0px 0px 16px 16px; + display: flex; + flex-direction: column; + align-items: center; +} + +html[data-platform~='windows linux macos'] #try-header, +html[data-platform~='windows linux macos'] #try-box { + display: block; +} + +#try-keyboard { + font-size: 1.5em; + width: 632px; + height: 44px; + margin: 0 auto 8px auto; + display: block; +} + +#osk-host { + width: 640px; + height: 300px; +} + +#try-keymanweb-link { + margin-top: 8px; + display: block; +} + /* Download boxes */ .download { diff --git a/developer/keymanweb/index.php b/developer/keymanweb/index.php index 0f1199df..1d479651 100644 --- a/developer/keymanweb/index.php +++ b/developer/keymanweb/index.php @@ -2,6 +2,7 @@ require_once('includes/template.php'); require_once __DIR__ . '/../../_includes/autoload.php'; use Keyman\Site\Common\KeymanHosts; + use Keyman\Site\com\keyman\KeymanWebHost; // Required head([ @@ -10,18 +11,7 @@ 'showMenu' => true ]); - $json = @file_get_contents("{$KeymanHosts->api_keyman_com}/version/web"); - if($json) { - $json = json_decode($json); - } - if($json && property_exists($json, 'version')) { - $build = $json->version; - } else { - // If the get-version API fails, we'll use the latest known stable version - $build = "16.0.145"; - } - - $cdnUrlBase = "{$KeymanHosts->s_keyman_com}/kmw/engine/$build"; + $cdnUrlBase = KeymanWebHost::getKeymanWebUrlBase(); ?> @@ -42,11 +32,11 @@ <script src='/keymanweb.js'></script> <script src='/kmwuitoggle.js'></script> <script> - (function(kmw) { - kmw.init({attachType:'auto'}); - kmw.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN) - kmw.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN) - })(keyman); + (function() { + keyman.init({attachType:'auto'}); + keyman.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN) + keyman.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN) + })(); </script>
From 3bf942ef23f0bc6f448cdfc0d6a61e592e18e127 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 22 Nov 2024 19:40:11 +0700 Subject: [PATCH 3/4] chore: override keymanweb z-index for hosted osk --- cdn/dev/keyboard-search/search.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdn/dev/keyboard-search/search.css b/cdn/dev/keyboard-search/search.css index ef2aaad2..bf49b8b0 100644 --- a/cdn/dev/keyboard-search/search.css +++ b/cdn/dev/keyboard-search/search.css @@ -342,6 +342,11 @@ html[data-platform~='windows linux macos'] #try-box { height: 300px; } +#osk-host .kmw-key-square { + /* Note: this is a hack to override the incorrect z-index that KMW is using for embedded OSK */ + z-index: auto; +} + #try-keymanweb-link { margin-top: 8px; display: block; From 70e89e35f183d2da3f8397e8bbdbefc5724b970b Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 25 Nov 2024 09:03:07 +0700 Subject: [PATCH 4/4] chore: address review comments --- _includes/2020/KeymanWebHost.php | 2 +- _includes/includes/ui/keyboard-details.php | 24 +++++++++++++++------- developer/keymanweb/index.php | 3 --- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/_includes/2020/KeymanWebHost.php b/_includes/2020/KeymanWebHost.php index a6441697..73455496 100644 --- a/_includes/2020/KeymanWebHost.php +++ b/_includes/2020/KeymanWebHost.php @@ -15,7 +15,7 @@ static function getKeymanWebUrlBase() { $build = $json->version; } else { // If the get-version API fails, we'll use the latest known stable version - $build = "16.0.145"; + $build = "17.0.332"; } return "{$KeymanHosts->s_keyman_com}/kmw/engine/$build"; diff --git a/_includes/includes/ui/keyboard-details.php b/_includes/includes/ui/keyboard-details.php index 6c780519..380116f0 100644 --- a/_includes/includes/ui/keyboard-details.php +++ b/_includes/includes/ui/keyboard-details.php @@ -6,8 +6,8 @@ require_once('includes/appstore.php'); use \DateTime; -use Keyman\Site\com\keyman\KeymanWebHost; -use \Keyman\Site\Common\KeymanHosts; + use \Keyman\Site\com\keyman\KeymanWebHost; + use \Keyman\Site\Common\KeymanHosts; define('GITHUB_ROOT', 'https://github.com/keymanapp/keyboards/tree/master/'); define('DOCUMENTATION_ROOT', KeymanHosts::Instance()->help_keyman_com . '/keyboard/'); @@ -122,7 +122,7 @@ protected static function download_box($platform) { } } - protected static function WriteWebBoxes() { + protected static function WriteWebBoxes($useDescription) { global $embed_target; global $KeymanHosts; if (isset(self::$keyboard->platformSupport->desktopWeb) && self::$keyboard->platformSupport->desktopWeb != 'none' && empty(self::$deprecatedBy)) { @@ -144,10 +144,18 @@ protected static function WriteWebBoxes() { } if (!isset($lang)) $lang = 'en'; $url = "{$KeymanHosts->keymanweb_com}/#$lang,Keyboard_" . self::$keyboard->id; - $description = htmlentities(self::$keyboard->name); + if($useDescription) { + $description = htmlentities(self::$keyboard->name); + $description = "
Use $description in your web browser. No need to install anything.
"; + $linktext = 'Use keyboard online'; + } else { + $description = ''; + $linktext = 'Full online editor'; + } return << - Full online editor + $linktext + $description
END; } @@ -372,8 +380,10 @@ protected static function WriteDownloadBoxes() { if ($embed == 'none') { if(self::GetWebDeviceFromPageDevice() == null) { - $webtext = self::WriteWebBoxes(); + $webtext = self::WriteWebBoxes(true); if ($webtext) { + // If we have a web keyboard, and we are not embedded, and this is a + // mobile device, then show the link to keymanweb.com echo $webtext; } } @@ -414,7 +424,7 @@ protected static function WriteKeymanWebBox() { return; } - $webtext = self::WriteWebBoxes(); + $webtext = self::WriteWebBoxes(false); $cdnUrlBase = KeymanWebHost::getKeymanWebUrlBase(); ?>

Try this keyboard

diff --git a/developer/keymanweb/index.php b/developer/keymanweb/index.php index 1d479651..3c625e5a 100644 --- a/developer/keymanweb/index.php +++ b/developer/keymanweb/index.php @@ -41,9 +41,6 @@ -

Upgrade Note: with KeymanWeb , the unminified version is no longer served from our CDN. -Instead, we use source maps to make the full source available in web developer tools.

-

Live Examples