Skip to content

Commit 8198b5c

Browse files
authored
Merge pull request #97 from amnuts/develop
Latest updates
2 parents a4af194 + 97b359e commit 8198b5c

File tree

7 files changed

+103
-39
lines changed

7 files changed

+103
-39
lines changed

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
A clean and responsive interface for Zend OPcache information, showing statistics, settings and cached files, and providing a real-time update for the information.
44

5-
This interface uses ReactJS and Axios and is for modern browsers and requires a minimum of PHP 7.1.
5+
This interface uses ReactJS and Axios and is for modern browsers, and requires a minimum of PHP 7.1.
66

77
## License
88

99
MIT: http://acollington.mit-license.org/
1010

1111
## Sponsoring this work
1212

13-
If you're able and would like to sponsor this work in some way, then that would be super awesome :heart:, and you can do so through the [GitHub Sponsorship](https://github.com/sponsors/amnuts) page.
13+
If you're able and would like to sponsor this work in some way, then that would be super awesome :heart:. You can do that through the [GitHub Sponsorship](https://github.com/sponsors/amnuts) page.
1414

15-
Alternatively, if you'd just like to give me a [shout-out on Twitter](https://twitter.com/acollington) to say you use it, that'd be awesome, too! (Any one else miss postcardware?)
15+
Alternatively, if you'd just like to give me a [shout-out on X (aka, Twitter)](https://twitter.com/acollington) to say you use it, then that'd be awesome, too! (Any one else miss postcardware?)
1616

1717
## Using the opcache-gui
1818

@@ -175,7 +175,9 @@ Also, if you choose to invalidate any files or reset the cache it will do this w
175175

176176
### Building it yourself
177177

178-
The interface has been split up to allow you to easily change the colours of the gui, the language shown, or even the core components, should you wish.
178+
The interface has been designed around the principle of having just one file that anyone needs in order to get up and running. To fulfil this, there's a template file, language files, jsx and css, which are all used in order to create the interface and they're brought together in the build process.
179+
180+
This build process will allow you to change the language used, how the required 3rd-party javascript libraries are included, the look and feel, or even the core components, should you wish.
179181

180182
#### The build command
181183

@@ -185,6 +187,7 @@ To run the build process, run the command `php ./build/build.php` from the repo
185187
🐢 Installing node modules
186188
🏗️ Building js and css
187189
🚀 Creating single build file
190+
🔗 Using remote js links from 'cloudflare'
188191
💯 Done!
189192
```
190193

@@ -208,13 +211,17 @@ Run the build script again should you make changes here.
208211

209212
The wrapper PHP template used in the build process, and that acts to pass various bits of data to the ReactJS side of things, is located at `build/template.phps`. If you wanted to update the version of ReactJS used, or how the wrapper html is structured (such as wanting to pass additional things to the ReactJS side of things), then this would be the file you'd want to update.
210213

211-
The template includes a few remote js files. If you want to make those local (for example, you have CSP policies in place and the remote urls are not whitelisted), then you can use the `-j` or `--local-js` flags when building, such as `php ./build/build.php -j`. This will fetch the remote script files and put them in the root of the repo, adjusting the links in the built `index.php` file to point to the local copies. If you want to build it again with remote files, run the command again without the flag.
214+
The interface requires a few 3rd-party js files to function correctly. You have the option of being able to change where these are fetched (between CloudFare, JSDelivr, and Unpkg), or you can have js js completely local and in-line (for example, you have CSP policies in place and the remote urls are not whitelisted).
215+
216+
In order to change the location of the 3rd-party resources, use the `-r` or `--remote-js` option followed by either `cloudflare`, `jsdelivr`, or `unpkg`. For example, if you wanted to use _jsdelivr_ then you'd run the build command like this: `php ./build/build.php -r jsdelivr`. This defaults to `cloudflare`.
217+
218+
If you wanted to have the js in-line, then you can use the `-j` or `--local-js` flag when building, such as `php ./build/build.php -j`. This will fetch the remote script files and embed the js into main `index.php` file. If you want to build it again with remote files, run the command again without the flag. Fetching the files will take your `-r` option into consideration if you provide it.
212219

213220
#### The language
214221

215222
There's an old saying that goes, "If you know more than one language you're multilingual, if you don't you're British." Not only is that a damning indictment of the British mentality towards other languages, but also goes to explain why the UI has only so far been in English - because I am, for all my sins, British.
216223

217-
However, it is now possible to build the interface with a different language. Currently, thanks to contributor, French is also support. If anyone else wants to contribute additional language packs, please submit a PR!
224+
However, it is now possible to build the interface with a different language. Currently, thanks to a contributor, French is also supported. If anyone else wants to contribute additional language packs, please submit a PR!
218225

219226
If the language pack is in the `build/_languages/` directory then you can use that with the `-l` or `--lang` flag. For example, if there is a `fr.json` language pack then you can use `php ./build/build.php -l fr` in order to build with that language.
220227

@@ -224,6 +231,14 @@ So to get started with a new language, copy the `example.json` to the language y
224231

225232
## Releases
226233

234+
**Version 3.5.0**\
235+
This version changes how the build process includes the javascript.
236+
* The `-j`/`--local-js` flag now embeds the javascript into the `index.php` file rather than having them as a separate files
237+
* The `-r`/`--remote-js` option has been added to allow you to decide where you get the 3rd-party files from (either when fetched locally or when added as remote script links), with `cloudflare`, `jsdelivr`, or `unpkg` being available options
238+
* CloudFlare has been set as the default for the remote js links
239+
* Added PR#94 from @M-Falken
240+
* Added PR#95 from @firassziedan
241+
227242
**Version 3.4.0**\
228243
This version adds a little more info about the files in the cache, and allows a bit more configuration though the config and build script.
229244
* Added new `datetime_format` config option for flexible formatting of date/time values

build/_frontend/interface.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,11 @@ function Footer(props) {
11661166
target="_blank"
11671167
title="opcache-gui (currently version {props.version}) on GitHub"
11681168
>https://github.com/amnuts/opcache-gui - version {props.version}</a>
1169+
1170+
<a className="sponsor-link" href="https://github.com/sponsors/amnuts"
1171+
target="_blank"
1172+
title="Sponsor this project and author on GitHub"
1173+
>Sponsor this project</a>
11691174
</footer>
11701175
);
11711176
}

build/_frontend/interface.scss

+13-7
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ $footer-border-color: #CCC;
286286

287287
.nav-tab-link-reset,
288288
.nav-tab-link-realtime,
289-
.github-link {
289+
.github-link,
290+
.sponsor-link {
290291
background-repeat: no-repeat;
291292
background-color: transparent;
292293
}
@@ -296,28 +297,33 @@ $footer-border-color: #CCC;
296297
background-position: 24px 50%;
297298
}
298299

299-
.github-link {
300-
background-position: 5px 50%;
301-
}
302-
303300
.main-footer {
304301
border-top: 1px solid $footer-border-color;
305302
padding: 1em 2em;
306303
}
307304

308-
.github-link {
305+
.github-link,
306+
.sponsor-link {
309307
background-position: 0 50%;
310308
padding: 2em 0 2em 2.3em;
311309
text-decoration: none;
312310
opacity: 0.7;
313-
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1.19em" height="1em" viewBox="0 0 1664 1408"><path d="M640 960q0 40-12.5 82t-43 76t-72.5 34t-72.5-34t-43-76t-12.5-82t12.5-82t43-76t72.5-34t72.5 34t43 76t12.5 82zm640 0q0 40-12.5 82t-43 76t-72.5 34t-72.5-34t-43-76t-12.5-82t12.5-82t43-76t72.5-34t72.5 34t43 76t12.5 82zm160 0q0-120-69-204t-187-84q-41 0-195 21q-71 11-157 11t-157-11q-152-21-195-21q-118 0-187 84t-69 204q0 88 32 153.5t81 103t122 60t140 29.5t149 7h168q82 0 149-7t140-29.5t122-60t81-103t32-153.5zm224-176q0 207-61 331q-38 77-105.5 133t-141 86t-170 47.5t-171.5 22t-167 4.5q-78 0-142-3t-147.5-12.5t-152.5-30t-137-51.5t-121-81t-86-115Q0 992 0 784q0-237 136-396q-27-82-27-170q0-116 51-218q108 0 190 39.5T539 163q147-35 309-35q148 0 280 32q105-82 187-121t189-39q51 102 51 218q0 87-27 168q136 160 136 398z" fill="#{toRGB($nav-icon-color)}"/></svg>');
314311
font-size: 80%;
315312

316313
&:hover {
317314
opacity: 1;
318315
}
319316
}
320317

318+
.github-link {
319+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1.19em" height="1em" viewBox="0 0 1664 1408"><path d="M640 960q0 40-12.5 82t-43 76t-72.5 34t-72.5-34t-43-76t-12.5-82t12.5-82t43-76t72.5-34t72.5 34t43 76t12.5 82zm640 0q0 40-12.5 82t-43 76t-72.5 34t-72.5-34t-43-76t-12.5-82t12.5-82t43-76t72.5-34t72.5 34t43 76t12.5 82zm160 0q0-120-69-204t-187-84q-41 0-195 21q-71 11-157 11t-157-11q-152-21-195-21q-118 0-187 84t-69 204q0 88 32 153.5t81 103t122 60t140 29.5t149 7h168q82 0 149-7t140-29.5t122-60t81-103t32-153.5zm224-176q0 207-61 331q-38 77-105.5 133t-141 86t-170 47.5t-171.5 22t-167 4.5q-78 0-142-3t-147.5-12.5t-152.5-30t-137-51.5t-121-81t-86-115Q0 992 0 784q0-237 136-396q-27-82-27-170q0-116 51-218q108 0 190 39.5T539 163q147-35 309-35q148 0 280 32q105-82 187-121t189-39q51 102 51 218q0 87-27 168q136 160 136 398z" fill="#{toRGB($nav-icon-color)}"/></svg>');
320+
}
321+
322+
.sponsor-link {
323+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path fill="crimson" d="M12 21.35l-1.45-1.32c-5.15-4.67-8.55-7.75-8.55-11.53 0-3.08 2.42-5.5 5.5-5.5 1.74 0 3.41.81 4.5 2.09 1.09-1.28 2.76-2.09 4.5-2.09 3.08 0 5.5 2.42 5.5 5.5 0 3.78-3.4 6.86-8.55 11.54l-1.45 1.31z"/></svg>');
324+
margin-left: 2em;
325+
}
326+
321327
.file-cache-only {
322328
margin-top: 0;
323329
}

build/build.php

+46-13
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,48 @@
44
* OPcache GUI - build script
55
*
66
* @author Andrew Collington, andy@amnuts.com
7-
* @version 3.4.0
7+
* @version 3.5.0
88
* @link https://github.com/amnuts/opcache-gui
99
* @license MIT, https://acollington.mit-license.org/
1010
*/
1111

12-
$options = getopt('jl:', ['local-js', 'lang:']);
12+
$remoteJsLocations = [
13+
'cloudflare' => [
14+
'cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js',
15+
'cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js',
16+
'cdnjs.cloudflare.com/ajax/libs/axios/1.3.6/axios.min.js',
17+
],
18+
'jsdelivr' => [
19+
'cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js',
20+
'cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js',
21+
'cdn.jsdelivr.net/npm/axios/dist/axios.min.js',
22+
],
23+
'unpkg' => [
24+
'unpkg.com/react@18/umd/react.production.min.js',
25+
'unpkg.com/react-dom@18/umd/react-dom.production.min.js',
26+
'unpkg.com/axios/dist/axios.min.js',
27+
],
28+
];
29+
$defaultRemoteJsFrom = array_keys($remoteJsLocations)[0];
30+
31+
$options = getopt('jr:l:', ['local-js', 'remote-js', 'lang:']);
1332
$makeJsLocal = (isset($options['j']) || isset($options['local-js']));
33+
$useRemoteJsFrom = $options['r'] ?? $options['remote-js'] ?? $defaultRemoteJsFrom;
1434
$useLanguage = $options['l'] ?? $options['lang'] ?? null;
1535
$languagePack = 'null';
1636
$parentPath = dirname(__DIR__);
1737

38+
if (!isset($remoteJsLocations[$useRemoteJsFrom])) {
39+
$validRemotes = implode(', ', array_keys($remoteJsLocations));
40+
echo "\nThe '{$useRemoteJsFrom}' remote js location is not valid - must be one of {$validRemotes} - defaulting to '{$defaultRemoteJsFrom}'\n\n";
41+
$useRemoteJsFrom = $defaultRemoteJsFrom;
42+
}
43+
1844
if ($useLanguage !== null) {
1945
$useLanguage = preg_replace('/[^a-z_-]/', '', $useLanguage);
2046
$languageFile = __DIR__ . "/_languages/{$useLanguage}.json";
2147
if (!file_exists($languageFile)) {
22-
echo "The '{$useLanguage}' file does not exist - using default English\n\n";
48+
echo "\nThe '{$useLanguage}' file does not exist - using default English\n\n";
2349
} else {
2450
$languagePack = "<<< EOJSON\n" . file_get_contents($languageFile) . "\nEOJSON";
2551
}
@@ -46,18 +72,25 @@
4672
[$jsOutput, $cssOutput, $phpOutput, $languagePack],
4773
$template
4874
);
75+
4976
if ($makeJsLocal) {
50-
echo "🔗 Making js links local\n";
51-
$jsTags = [];
52-
$matched = preg_match_all('!<script src="([^"]*)"></script>!', $output, $jsTags);
53-
if ($matched) {
54-
foreach ($jsTags[1] as $jsUrl) {
55-
$jsFile = basename($jsUrl);
56-
$jsFilePath = $parentPath . '/' . $jsFile;
57-
file_put_contents($jsFilePath, file_get_contents('https:' . $jsUrl));
58-
$output = str_replace($jsUrl, $jsFile, $output);
59-
}
77+
echo "🔗 Making js locally in-line\n";
78+
$jsContents = [];
79+
foreach ($remoteJsLocations[$useRemoteJsFrom] as $jsUrl) {
80+
$jsContents[] = file_get_contents('https://' . $jsUrl);
6081
}
82+
$output = str_replace('{{JS_LIBRARIES}}',
83+
"<script>\n" . implode(";\n\n", $jsContents) . ";\n</script>",
84+
$output
85+
);
86+
} else {
87+
echo "🔗 Using remote js links from '{$useRemoteJsFrom}'\n";
88+
$output = str_replace('{{JS_LIBRARIES}}',
89+
implode("\n ", array_map(static function ($jsUrl) {
90+
return "<script src=\"//{$jsUrl}\"></script>";
91+
}, $remoteJsLocations[$useRemoteJsFrom])),
92+
$output
93+
);
6194
}
6295

6396
file_put_contents($parentPath . '/index.php', $output);

build/template.phps

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Amnuts\Opcache;
88
* A simple but effective single-file GUI for the OPcache PHP extension.
99
*
1010
* @author Andrew Collington, andy@amnuts.com
11-
* @version 3.4.0
11+
* @version 3.5.0
1212
* @link https://github.com/amnuts/opcache-gui
1313
* @license MIT, https://acollington.mit-license.org/
1414
*/
@@ -69,10 +69,9 @@ $opcache = (new Service($options))->handle();
6969
<head>
7070
<meta charset="UTF-8">
7171
<meta name="viewport" content="width=device-width,initial-scale=1.0">
72+
<meta name="robots" content="noindex, nofollow" />
7273
<title>OPcache statistics on <?= $opcache->getData('version', 'host'); ?></title>
73-
<script src="//unpkg.com/react/umd/react.production.min.js"></script>
74-
<script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
75-
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
74+
{{JS_LIBRARIES}}
7675
<style>
7776
{{CSS_OUTPUT}}
7877
</style>

0 commit comments

Comments
 (0)