PluginProbe
User Access Manager / trunk
User Access Manager vtrunk
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Backend / Administration / AboutController.php

AboutController.php in User Access Manager trunk, at src/Controller/Backend/Administration/AboutController.php

63 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Controller\Backend\Administration;
6
7 use UserAccessManager\Controller\Controller;
8
9 class AboutController extends Controller
10 {
11 public const SUPPORTER_FILE = 'supporters.json';
12 public const SUPPORTER_FILE_URL = 'https://gm-alex.github.io/user-access-manager/supporters.json';
13
14 private const SUPPORTER_FILE_LIFETIME_IN_SECONDS = 24 * 60 * 60;
15
16 protected ?string $template = 'AdminAbout.php';
17 private ?array $supporters = null;
18
19 private function getAllSupporters(): ?array
20 {
21 if ($this->supporters !== null) {
22 return $this->supporters;
23 }
24
25 $realPath = rtrim($this->wordpressConfig->getRealPath(), DIRECTORY_SEPARATOR);
26 $fileWithPath = $realPath . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . self::SUPPORTER_FILE;
27
28 $needsUpdate = $this->php->isFile($fileWithPath) === false
29 || $this->php->fileMTime($fileWithPath)
30 < $this->wordpress->currentTime('timestamp') - self::SUPPORTER_FILE_LIFETIME_IN_SECONDS;
31
32 $fileContent = ($needsUpdate === true) ? $this->php->fileGetContents(self::SUPPORTER_FILE_URL) : false;
33
34 if ($fileContent !== false) {
35 $this->php->filePutContents($fileWithPath, $fileContent);
36 } elseif ($this->php->isFile($fileWithPath) === true) {
37 $fileContent = $this->php->fileGetContents($fileWithPath);
38 }
39
40 return $this->supporters = (is_string($fileContent) === true) ? json_decode($fileContent, true) : [];
41 }
42
43 private function getSupporterGroup(string $key): array
44 {
45 return $this->getAllSupporters()[$key] ?? [];
46 }
47
48 public function getSpecialThanks(): array
49 {
50 return $this->getSupporterGroup('special-thanks');
51 }
52
53 public function getTopSupporters(): array
54 {
55 return $this->getSupporterGroup('top-supporters');
56 }
57
58 public function getSupporters(): array
59 {
60 return $this->getSupporterGroup('supporters');
61 }
62 }
63