Skip to content

Commit 13d3865

Browse files
Merge pull request #629 from keymanapp/auto/A19S17-merge-master-into-staging
auto: A19S17 merge master into staging
2 parents 6496bb4 + a1dd045 commit 13d3865

File tree

37 files changed

+1808
-1085
lines changed

37 files changed

+1808
-1085
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,47 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3.5.2
14+
uses: actions/checkout@v4.1.5
1515

1616
- name: Build the docker image for keyman.com app
1717
shell: bash
1818
run: |
1919
echo "TIER_TEST" > tier.txt
20-
./build.sh build start
20+
./build.sh configure build start --debug
2121
env:
2222
fail-fast: true
2323

2424
#
2525
# Finally, run the tests
2626
#
27+
- name: PHP test
28+
shell: bash
29+
run: |
30+
docker exec keyman-com-app sh -c "vendor/bin/phpunit --testdox"
31+
2732
- name: Lint
2833
shell: bash
2934
run: |
3035
( set +e; set +o pipefail; find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\n' php -l | grep -v "No syntax errors detected"; exit ${PIPESTATUS[2]} )
3136
3237
- name: Check broken links
3338
shell: bash
39+
continue-on-error: false
40+
# Exclude checking locales for each link 'lang=*'
41+
run: |
42+
set +e
43+
set +o pipefail
44+
npx broken-link-checker http://localhost:8053/_test --recursive --ordered ---host-requests 50 -e --filter-level 3 --exclude '*/donate' --exclude '*lang=*' | tee blc.log
45+
echo "BLC_RESULT=${PIPESTATUS[0]}" >> "$GITHUB_ENV"
46+
47+
- name: Report on broken links
3448
run: |
35-
set +e;
36-
set +o pipefail;
37-
npx broken-link-checker http://localhost:8053/_test --ordered --recursive --host-requests 50 -e --filter-level 3 --exclude '*/donate' | \
49+
set +e
50+
set +o pipefail
51+
cat blc.log | \
3852
grep -E "BROKEN|Getting links from" | \
39-
grep -B 1 "BROKEN"
40-
exit ${PIPESTATUS[0]}
53+
grep -B 1 "BROKEN";
54+
exit "${BLC_RESULT}"
4155
4256
- name: Check PHP errors
4357
shell: bash

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ cdn/deploy/
44

55
tier.txt
66

7+
# unit test artifacts
8+
blc.log
9+
.phpunit.result.cache
10+
711
vendor*
812
/node_modules/
913

.htaccess

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ RewriteRule "^(macosx|macos)\b(.*)$" "/mac$2" [NC,R=301,END,QSA]
3434
# Redirect deprecated Google Plus link
3535
RewriteRule "^plus.*" "/" [NC,R=301,END,QSA]
3636

37+
# Redirect PHP unit tests
38+
RewriteRule "^tests(\/.*)?" "/" [NC,R=301,END,QSA]
39+
3740
# /donate -> donate.keyman.com
3841
RedirectMatch 301 "^(?i)/donate(\/.*)?" "https://donate.keyman.com"
3942

@@ -93,7 +96,7 @@ RewriteRule "^keyboards/download/([^/]+)$" "/keyboards/keyboard.php?id=$1" [END,
9396

9497
# /keyboards/share/[id] to /keyboards/share.php
9598
# if the keyboard exists in the repo, then share.php will redirect to /keyboards/<id>
96-
RewriteRule "^keyboards/share/([^/]+)$" "/keyboards/share.php?id=$1" [END]
99+
RewriteRule "^keyboards/share/([^/]+)$" "/keyboards/share.php?id=$1" [END,QSA]
97100

98101
# /keyboards/{id}.json to /keyboards/keyboard.json.php
99102
RewriteRule "^keyboards/(?!keyboard.json)(.*)\.json$" "/keyboards/keyboard.json.php?id=$1" [END]

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# syntax=docker/dockerfile:1
2+
3+
ARG BUILDER_CONFIGURATION="release"
24
FROM php:7.4-apache@sha256:c9d7e608f73832673479770d66aacc8100011ec751d1905ff63fae3fe2e0ca6d AS composer-builder
35

46
# Install Zip to use composer
@@ -15,7 +17,14 @@ RUN composer self-update
1517
USER www-data
1618
WORKDIR /composer
1719
COPY composer.* /composer/
18-
RUN composer install
20+
# Consume the build argment
21+
ARG BUILDER_CONFIGURATION
22+
RUN if [ "$BUILDER_CONFIGURATION" = "debug" ]; then \
23+
# composer install --dev deprecated
24+
COMPOSER_NO_DEV=0 composer install ; \
25+
else \
26+
COMPOSER_NO_DEV=1 composer install ; \
27+
fi
1928

2029
# Site
2130
FROM php:7.4-apache@sha256:c9d7e608f73832673479770d66aacc8100011ec751d1905ff63fae3fe2e0ca6d

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ shell, and from this folder, run:
5252
./build.sh build
5353
```
5454

55+
If you'll be running tests locally, the Docker image will need to be built with dev dependencies:
56+
57+
```sh
58+
./build.sh build --debug
59+
```
60+
5561
#### Start the Docker container
5662

5763
To start up the website, in bash, run:
@@ -81,7 +87,11 @@ In bash, run:
8187

8288
#### Running tests
8389

84-
To check for broken links and .php file conformance, when the site is running,
90+
When the site is running, the test action will do the following:
91+
* PHP unit tests
92+
* Check .php file conformance
93+
* Check for internal broken links
94+
8595
in bash, run:
8696

8797
```sh

_includes/2020/templates/Foot.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static function render(array $fields = []) {
3838
</div>
3939
<!--End mc_embed_signup-->
4040
<br>
41+
<div id="low-frequency">Receive updates 3-4 times/year, or you can<br><a href="https://blog.keyman.com/subscribe/">get regular updates</a> every 2 weeks</div>
4142
<div id="privacy-policy"><a href="/privacy/">Privacy policy</a></div>
4243

4344
<div id='footer-get-involved'>

_includes/2020/templates/Menu.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,63 @@ public static function render(array $fields): void {
2929
Menu::render_top_menu($fields);
3030
}
3131

32+
/**
33+
* Generate the URL with query to change the UI language
34+
* @param language - language tag to use
35+
*/
36+
private static function change_ui_language($language): string {
37+
// Parse the current URI for populating the UI dropdown
38+
$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
39+
$parts = parse_url($url);
40+
41+
if (!empty($parts['query'])) {
42+
parse_str($parts['query'], $queryParams);
43+
} else {
44+
$queryParams = [];
45+
}
46+
47+
// Set the language query
48+
$queryParams['lang'] = $language;
49+
$query = http_build_query($queryParams);
50+
51+
return $parts['path'] . "?" . $query;
52+
}
53+
54+
/**
55+
* Render the globe dropdown for changing the UI language
56+
* As UI languages get added, we'll need to update this.
57+
* Limitation: Currently only visible on pages that use localized strings
58+
* @param number - Div number, default 0.
59+
*/
60+
private static function render_globe_dropdown($number = 0): void {
61+
global $page_is_using_locale;
62+
if (!isset($page_is_using_locale) || !$page_is_using_locale) {
63+
// only render on pages that use localized strings
64+
return;
65+
}
66+
67+
$divID = ($number == 1) ? "ui-language1" : "ui-language";
68+
echo <<<END
69+
<p>
70+
<div id='$divID' class="menu-item">
71+
END;
72+
?>
73+
<img src="<?php echo Util::cdn("img/globe.png"); ?>" alt="UI globe dropdown" />
74+
<div class="menu-item-dropdown">
75+
<div class="menu-dropdown-inner">
76+
<ul>
77+
<!-- Just use autonyms -->
78+
<li><a href="<?= Menu::change_ui_language('en'); ?>">English</a></li>
79+
<li><a href="<?= Menu::change_ui_language('es'); ?>">Español</a></li>
80+
<li><a href="<?= Menu::change_ui_language('fr'); ?>">Français</a></li>
81+
</ul>
82+
</div>
83+
</div>
84+
</div>
85+
</p>
86+
<?php
87+
}
88+
3289
private static function render_phone_menu(object $fields): void {
3390
?>
3491

@@ -117,6 +174,9 @@ private static function render_top_menu(object $fields): void {
117174
</form>
118175
<p id="donate"><a href="/donate">Donate</a></p>
119176
<p><a href="<?= KeymanHosts::Instance()->help_keyman_com ?>" target="blank">Support<img src="<?php echo Util::cdn("img/helpIcon.png"); ?>" alt="help icon"></a></p>
177+
<?php
178+
Menu::render_globe_dropdown();
179+
?>
120180
</div>
121181
</div>
122182
<div id="top-menu-bg"></div>
@@ -132,6 +192,9 @@ private static function render_top_menu(object $fields): void {
132192
</form>
133193
<a id='help1-donate' href="/donate">Donate</a>
134194
<a href="<?= KeymanHosts::Instance()->help_keyman_com ?>"><img id="top-menu-icon2" src="<?php echo Util::cdn("img/helpIcon.png"); ?>" alt="help icon" /></a>
195+
<?php
196+
Menu::render_globe_dropdown(1);
197+
?>
135198
</div>
136199
<div class="wrapper">
137200
<div class="menu-item" id="keyboards">

_includes/autoload.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
if(preg_match('/^Keyman\\\\Site\\\\com\\\\keyman\\\\(.+)/', $class_name, $matches)) {
66
// Fix namespace pathing for Linux
77
$filename = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $matches[1]);
8-
$success = include(__DIR__ . "/2020/{$filename}.php");
8+
if ($filename == 'Locale') {
9+
$success = include(__DIR__ . "/locale/{$filename}.php");
10+
} else {
11+
$success = include(__DIR__ . "/2020/{$filename}.php");
12+
}
913
if($success === FALSE) {
1014
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
1115
die("Unable to find class $class_name");

_includes/includes/template.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44
// *Don't* use autoloader here because of potential side-effects in older pages
55
require_once(__DIR__ . '/../2020/Util.php');
6+
require_once(__DIR__ . '/../locale/Locale.php');
67
require_once(__DIR__ . '/../../_common/KeymanVersion.php');
78
require_once(__DIR__ . '/../2020/templates/Head.php');
89

10+
use Keyman\Site\com\keyman\Locale;
11+
912
function template_finish($foot) {
1013
//ob_end_flush();
1114

0 commit comments

Comments
 (0)