Skip to content

Commit d01fe94

Browse files
committed
merge master
1 parent 73e0baa commit d01fe94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5210
-1660
lines changed

app/controllers/DocsController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public function pluginGet(string $language, string $version, string $plugin_name
156156
public function singlePageGet(string $language, string $version) {
157157
$app = $this->app;
158158

159+
// Check if the language is valid
160+
if ($this->DocsLogic->checkValidLanguage($language) === false) {
161+
$language = 'en';
162+
}
163+
164+
// Check if the version is valid
165+
if ($this->DocsLogic->checkValidVersion($version) === false) {
166+
$version = 'v3';
167+
}
168+
159169
// recursively look through all the content files, and pull out each section and render it
160170
$sections = [];
161171
$language_directory = self::CONTENT_DIR . '/' . $version . '/' . $language . '/';

app/utils/CustomFlight.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* This is only for autocomplete help.
13-
*
13+
* @deprecated
1414
* @method Cache cache()
1515
* @method LatteEngine latte()
1616
* @method Parsedown parsedown()

app/utils/DocsLogic.php

Lines changed: 129 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@
99
use flight\Engine;
1010

1111
class DocsLogic {
12-
public function __construct(protected Engine $app) {
13-
//
14-
}
15-
16-
/**
17-
* Renders a page using the specified Latte template file and parameters.
18-
*
19-
* @param string $latte_file The path to the Latte template file to be rendered.
20-
* @param array $params An optional array of parameters to be passed to the template.
21-
*/
12+
const AVAILABLE_LANGUAGES = [
13+
'en',
14+
'es',
15+
'fr',
16+
'lv',
17+
'pt',
18+
'de',
19+
'ru',
20+
'zh',
21+
'ja',
22+
'ko',
23+
'uk',
24+
'id'
25+
];
26+
27+
public function __construct(protected Engine $app) {
28+
}
29+
30+
/**
31+
* Renders a page using the specified Latte template file and parameters.
32+
*
33+
* @param string $latte_file The path to the Latte template file to be rendered.
34+
* @param array $params An optional array of parameters to be passed to the template.
35+
*/
2236
public function renderPage(string $latte_file, array $params = []) {
2337
$request = $this->app->request();
2438
$uri = $request->url;
@@ -33,89 +47,109 @@ public function renderPage(string $latte_file, array $params = []) {
3347
$this->app->latte()->render($latte_file, $params);
3448
}
3549

36-
/**
37-
* Sets up the translator service with the specified language and version.
38-
*
39-
* @param string $language The language to be used by the translator.
40-
* @param string $version The version of the translation service.
41-
* @return Translator The configured translator service.
42-
*/
43-
public function setupTranslatorService(string $language, string $version): Translator {
44-
$Translator = $this->app->translator();
45-
$Translator->setLanguage($language);
46-
$Translator->setVersion($version);
50+
/**
51+
* Sets up the translator service with the specified language and version.
52+
*
53+
* @param string $language The language to be used by the translator.
54+
* @param string $version The version of the translation service.
55+
* @return Translator The configured translator service.
56+
*/
57+
public function setupTranslatorService(string $language, string $version): Translator {
58+
$Translator = $this->app->translator();
59+
$Translator->setLanguage($language);
60+
$Translator->setVersion($version);
4761
return $Translator;
48-
}
49-
50-
/**
51-
* Compiles a single page based on the specified language, version, and section.
52-
*
53-
* @param string $language The language of the page to compile.
54-
* @param string $version The version of the page to compile.
55-
* @param string $section The section of the page to compile.
56-
*
57-
* @return void
58-
*/
62+
}
63+
64+
/**
65+
* Compiles a single page based on the specified language, version, and section.
66+
*
67+
* @param string $language The language of the page to compile.
68+
* @param string $version The version of the page to compile.
69+
* @param string $section The section of the page to compile.
70+
*
71+
* @return void
72+
*/
5973
public function compileSinglePage(string $language, string $version, string $section) {
6074
$app = $this->app;
6175

62-
$Translator = $this->setupTranslatorService($language, $version);
76+
// Check if the language is valid
77+
if ($this->checkValidLanguage($language) === false) {
78+
$language = 'en';
79+
}
80+
81+
// Check if the version is valid
82+
if ($this->checkValidVersion($version) === false) {
83+
$version = 'v3';
84+
}
85+
86+
$Translator = $this->setupTranslatorService($language, $version);
6387

64-
$cacheStartTime = microtime(true);
65-
$cacheHit = true;
66-
$cacheKey = $section . '_html_' . $language . '_' . $version;
67-
$markdown_html = $app->cache()->retrieve($cacheKey);
68-
if ($markdown_html === null) {
69-
$cacheHit = false;
70-
$markdown_html = $app->parsedown()->text($Translator->getMarkdownLanguageFile($section . '.md'));
71-
$markdown_html = Text::addClassesToElements($markdown_html);
72-
$app->cache()->store($cacheKey, $markdown_html, 86400); // 1 day
73-
}
88+
$cacheStartTime = microtime(true);
89+
$cacheHit = true;
90+
$cacheKey = $section . '_html_' . $language . '_' . $version;
91+
$markdown_html = $app->cache()->retrieve($cacheKey);
92+
if ($markdown_html === null) {
93+
$cacheHit = false;
94+
$markdown_html = $app->parsedown()->text($Translator->getMarkdownLanguageFile($section . '.md'));
95+
$markdown_html = Text::addClassesToElements($markdown_html);
96+
$app->cache()->store($cacheKey, $markdown_html, 86400); // 1 day
97+
}
7498

75-
$app->eventDispatcher()->trigger('flight.cache.checked', 'compile_single_page_'.$cacheKey, $cacheHit, microtime(true) - $cacheStartTime);
99+
$app->eventDispatcher()->trigger('flight.cache.checked', 'compile_single_page_' . $cacheKey, $cacheHit, microtime(true) - $cacheStartTime);
76100

77101
$markdown_html = $this->wrapContentInDiv($markdown_html);
78102

79103
$this->renderPage('single_page.latte', [
80104
'page_title' => $section,
81105
'markdown' => $markdown_html,
82-
'version' => $version,
106+
'version' => $version,
83107
]);
84108
}
85109

86-
/**
87-
* Compiles the Scrollspy page based on the provided language, version, section, and sub-section.
88-
*
89-
* @param string $language The language of the documentation.
90-
* @param string $version The version of the documentation.
91-
* @param string $section The main section of the documentation.
92-
* @param string $sub_section The sub-section of the documentation.
93-
*/
110+
/**
111+
* Compiles the Scrollspy page based on the provided language, version, section, and sub-section.
112+
*
113+
* @param string $language The language of the documentation.
114+
* @param string $version The version of the documentation.
115+
* @param string $section The main section of the documentation.
116+
* @param string $sub_section The sub-section of the documentation.
117+
*/
94118
public function compileScrollspyPage(string $language, string $version, string $section, string $sub_section) {
95119
$app = $this->app;
96120

97-
$Translator = $this->setupTranslatorService($language, $version);
121+
// Check if the language is valid
122+
if ($this->checkValidLanguage($language) === false) {
123+
$language = 'en';
124+
}
125+
126+
// Check if the version is valid
127+
if ($this->checkValidVersion($version) === false) {
128+
$version = 'v3';
129+
}
130+
131+
$Translator = $this->setupTranslatorService($language, $version);
98132

99-
$section_file_path = str_replace('_', '-', $section);
133+
$section_file_path = str_replace('_', '-', $section);
100134
$sub_section_underscored = str_replace('-', '_', $sub_section);
101135
$heading_data = $app->cache()->retrieve($sub_section_underscored . '_heading_data_' . $language . '_' . $version);
102136

103-
$cacheStartTime = microtime(true);
104-
$cacheHit = true;
105-
$cacheKey = $sub_section_underscored . '_html_' . $language . '_' . $version;
106-
$markdown_html = $app->cache()->retrieve($cacheKey);
107-
if ($markdown_html === null) {
108-
$cacheHit = false;
109-
$markdown_html = $app->parsedown()->text($Translator->getMarkdownLanguageFile('/' . $section_file_path . '/' . $sub_section_underscored . '.md'));
137+
$cacheStartTime = microtime(true);
138+
$cacheHit = true;
139+
$cacheKey = $sub_section_underscored . '_html_' . $language . '_' . $version;
140+
$markdown_html = $app->cache()->retrieve($cacheKey);
141+
if ($markdown_html === null) {
142+
$cacheHit = false;
143+
$markdown_html = $app->parsedown()->text($Translator->getMarkdownLanguageFile('/' . $section_file_path . '/' . $sub_section_underscored . '.md'));
110144

111145
$heading_data = [];
112-
$markdown_html = Text::generateAndConvertHeaderListFromHtml($markdown_html, $heading_data, 'h2', $section_file_path.'/'.$sub_section);
113-
$markdown_html = Text::addClassesToElements($markdown_html);
146+
$markdown_html = Text::generateAndConvertHeaderListFromHtml($markdown_html, $heading_data, 'h2', $section_file_path . '/' . $sub_section);
147+
$markdown_html = Text::addClassesToElements($markdown_html);
114148
$app->cache()->store($sub_section_underscored . '_heading_data_' . $language . '_' . $version, $heading_data, 86400); // 1 day
115-
$app->cache()->store($cacheKey, $markdown_html, 86400); // 1 day
116-
}
149+
$app->cache()->store($cacheKey, $markdown_html, 86400); // 1 day
150+
}
117151

118-
$app->eventDispatcher()->trigger('flight.cache.checked', 'compile_scrollspy_page_'.$cacheKey, $cacheHit, microtime(true) - $cacheStartTime);
152+
$app->eventDispatcher()->trigger('flight.cache.checked', 'compile_scrollspy_page_' . $cacheKey, $cacheHit, microtime(true) - $cacheStartTime);
119153

120154
// pull the title out of the first h1 tag
121155
$page_title = '';
@@ -133,17 +167,17 @@ public function compileScrollspyPage(string $language, string $version, string $
133167
'custom_page_title' => ($page_title ? $page_title . ' - ' : '') . $Translator->translate($section),
134168
'markdown' => $markdown_html,
135169
'heading_data' => $heading_data,
136-
'relative_uri' => '/'.$section_file_path,
137-
'version' => $version,
170+
'relative_uri' => '/' . $section_file_path,
171+
'version' => $version,
138172
]);
139173
}
140174

141-
/**
175+
/**
142176
* This is necessary to encapsulate contents (<p>, <pre>, <ol>, <ul>)
143177
* in a div which can be then styled with CSS thanks to the class name `flight-block`
144-
*
145-
* @param string $html
146-
* @return string
178+
*
179+
* @param string $html
180+
* @return string
147181
*/
148182
protected function wrapContentInDiv(string $html): string {
149183
$dom = new DOMDocument;
@@ -189,8 +223,8 @@ protected function wrapContentInDiv(string $html): string {
189223
&& $element->nodeName !== 'ol'
190224
&& $element->nodeName !== 'ul'
191225
&& $element->nodeName !== 'blockquote'
192-
&& $element->nodeName !== 'table'
193-
&& $element->nodeName !== 'dl'
226+
&& $element->nodeName !== 'table'
227+
&& $element->nodeName !== 'dl'
194228
&& is_null($div) === false
195229
) {
196230
$d .= '</div>';
@@ -208,4 +242,24 @@ protected function wrapContentInDiv(string $html): string {
208242

209243
return $d;
210244
}
245+
246+
/**
247+
* Checks if the provided language is valid.
248+
*
249+
* @param string $language The language code to check.
250+
* @return bool True if the language is valid, false otherwise.
251+
*/
252+
public function checkValidLanguage(string $language): bool {
253+
return in_array($language, self::AVAILABLE_LANGUAGES, true) === true;
254+
}
255+
256+
/**
257+
* Checks if the provided version is valid.
258+
*
259+
* @param string $version The version code to check.
260+
* @return bool True if the version is valid, false otherwise.
261+
*/
262+
public function checkValidVersion(string $version): bool {
263+
return in_array($version, ['v3', 'v2'], true) === true;
264+
}
211265
}

app/views/banner.latte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="d-none d-md-block col-md-4 text-right">
33
<img
44
class="flight-light-image img-fluid"
5-
src="./images/left.png"
5+
src="/images/left.png"
66
alt="Icons background left side" />
77
<img
88
class="flight-dark-image img-fluid"
9-
src="./images/left-dark.png"
9+
src="/images/left-dark.png"
1010
alt="Icons background left side in dark variant" />
1111
</div>
1212
<div class="col-md-4 col-12 text-center">
@@ -21,11 +21,11 @@
2121
<div class="col-md-4 d-none d-md-block">
2222
<img
2323
class="flight-light-image img-fluid"
24-
src="./images/right.png"
24+
src="/images/right.png"
2525
alt="Icons background right side" />
2626
<img
2727
class="flight-dark-image img-fluid"
28-
src="./images/right-dark.png"
28+
src="/images/right-dark.png"
2929
alt="Icons background right side in dark variant" />
3030
</div>
3131
</div>

app/views/links.latte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
<link
1616
rel="stylesheet"
1717
href="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/css/autoComplete.min.css" />
18-
<link rel="stylesheet" href="./css/style.css?version=7" />
18+
<link rel="stylesheet" href="/css/style.css?version=7" />
1919

2020
{foreach ['en', 'fr', 'es', 'pt', 'lv', 'de', 'ru', 'zh', 'ja', 'ko', 'uk', 'id'] as $lang}
2121
<link rel="alternate" hreflang="{$lang}" href="./?lang={$lang}" />
2222
{/foreach}
2323

24-
<link rel="icon" type="image/png" href="./images/favicon.png" />
24+
<link rel="icon" type="image/png" href="/images/favicon.png" />
2525

2626
<!-- to prevent page flash -->
2727
<script
2828
nonce="{$nonce}"
29-
src="./js/color-mode-toggler.js"></script>
29+
src="/js/color-mode-toggler.js"></script>

app/views/logo.latte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<figure class="m-0">
22
<img
33
class="flight-light-image"
4-
src="./images/logo-flight.png"
4+
src="/images/logo-flight.png"
55
alt="Flight logo"
66
height="30" />
77
<img
88
class="flight-dark-image"
9-
src="./images/logo-flight-dark.png"
9+
src="/images/logo-flight-dark.png"
1010
alt="Flight logo dark variant"
1111
height="30" />
1212
</figure>

app/views/scripts.latte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script
22
nonce="{$nonce}"
3-
src="./js/color-mode-toggler.js"></script>
3+
src="/js/color-mode-toggler.js"></script>
44
<script async defer src="https://buttons.github.io/buttons.js"></script>
55
<script
66
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
@@ -10,7 +10,7 @@
1010

1111
<!-- Google tag (gtag.js) -->
1212
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3C36SDZ8FE"></script>
13-
<script nonce="{$nonce}" src="./js/gtag.js"></script>
13+
<script nonce="{$nonce}" src="/js/gtag.js"></script>
1414

1515
<script
1616
src="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/autoComplete.min.js"></script>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php": "^8.2",
1919
"ext-json": "*",
2020
"erusev/parsedown": "^1.7",
21-
"flightphp/apm": "^0.1.1",
21+
"flightphp/apm": "^0.2",
2222
"flightphp/cache": "^1.0",
2323
"flightphp/container": "^1.1",
2424
"flightphp/core": "^3.15",

0 commit comments

Comments
 (0)