| 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 |
|