PluginProbe
User Access Manager / 2.3.0
User Access Manager v2.3.0
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 / AboutController.php

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

58 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;
6
7 use UserAccessManager\Controller\Controller;
8
9 class AboutController extends Controller
10 {
11 const SUPPORTER_FILE = 'supporters.json';
12 const SUPPORTER_FILE_URL = 'https://gm-alex.github.io/user-access-manager/supporters.json';
13
14 protected ?string $template = 'AdminAbout.php';
15 private ?array $supporters = null;
16
17 private function getAllSupporters(): ?array
18 {
19 if ($this->supporters === null) {
20 $realPath = rtrim($this->wordpressConfig->getRealPath(), DIRECTORY_SEPARATOR);
21 $path = [$realPath, 'assets'];
22 $path = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR;
23 $fileWithPath = $path . self::SUPPORTER_FILE;
24 $needsUpdate = is_file($fileWithPath) === false
25 || filemtime($fileWithPath) < $this->wordpress->currentTime('timestamp') - 24 * 60 * 60;
26 $fileContent = ($needsUpdate === true) ? @file_get_contents(self::SUPPORTER_FILE_URL) : false;
27
28 if ($fileContent !== false) {
29 file_put_contents($fileWithPath, $fileContent);
30 } elseif (is_file($fileWithPath) === true) {
31 $fileContent = file_get_contents($fileWithPath);
32 }
33
34 $this->supporters = (is_string($fileContent) === true) ? json_decode($fileContent, true) : [];
35 }
36
37 return $this->supporters;
38 }
39
40 public function getSpecialThanks(): array
41 {
42 $supporters = $this->getAllSupporters();
43 return isset($supporters['special-thanks']) === true ? $supporters['special-thanks'] : [];
44 }
45
46 public function getTopSupporters(): array
47 {
48 $supporters = $this->getAllSupporters();
49 return isset($supporters['top-supporters']) === true ? $supporters['top-supporters'] : [];
50 }
51
52 public function getSupporters(): array
53 {
54 $supporters = $this->getAllSupporters();
55 return isset($supporters['supporters']) === true ? $supporters['supporters'] : [];
56 }
57 }
58