PluginProbe
User Access Manager / 2.2.16
User Access Manager v2.2.16
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.2.16, at src/Controller/Backend/AboutController.php

99 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AboutController.php
4 *
5 * The AboutController class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Backend;
19
20 use UserAccessManager\Controller\Controller;
21
22 /**
23 * Class AboutController
24 *
25 * @package UserAccessManager\Controller
26 */
27 class AboutController extends Controller
28 {
29 const SUPPORTER_FILE = 'supporters.json';
30 const SUPPORTER_FILE_URL = 'https://gm-alex.github.io/user-access-manager/supporters.json';
31
32 /**
33 * @var string
34 */
35 protected $template = 'AdminAbout.php';
36
37 /**
38 * @var null|array
39 */
40 private $supporters = null;
41
42 /**
43 * Returns all the supporters.
44 * @return array
45 */
46 private function getAllSupporters(): ?array
47 {
48 if ($this->supporters === null) {
49 $realPath = rtrim($this->wordpressConfig->getRealPath(), DIRECTORY_SEPARATOR);
50 $path = [$realPath, 'assets'];
51 $path = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR;
52 $fileWithPath = $path . self::SUPPORTER_FILE;
53 $needsUpdate = is_file($fileWithPath) === false
54 || filemtime($fileWithPath) < $this->wordpress->currentTime('timestamp') - 24 * 60 * 60;
55 $fileContent = ($needsUpdate === true) ? @file_get_contents(self::SUPPORTER_FILE_URL) : false;
56
57 if ($fileContent !== false) {
58 file_put_contents($fileWithPath, $fileContent);
59 } elseif (is_file($fileWithPath) === true) {
60 $fileContent = file_get_contents($fileWithPath);
61 }
62
63 $this->supporters = (is_string($fileContent) === true) ? json_decode($fileContent, true) : [];
64 }
65
66 return $this->supporters;
67 }
68
69 /**
70 * Returns the people which earn a special thanks.
71 * @return array
72 */
73 public function getSpecialThanks(): array
74 {
75 $supporters = $this->getAllSupporters();
76 return isset($supporters['special-thanks']) === true ? $supporters['special-thanks'] : [];
77 }
78
79 /**
80 * Returns the people which earn a special thanks.
81 * @return array
82 */
83 public function getTopSupporters(): array
84 {
85 $supporters = $this->getAllSupporters();
86 return isset($supporters['top-supporters']) === true ? $supporters['top-supporters'] : [];
87 }
88
89 /**
90 * Returns the people which earn a special thanks.
91 * @return array
92 */
93 public function getSupporters(): array
94 {
95 $supporters = $this->getAllSupporters();
96 return isset($supporters['supporters']) === true ? $supporters['supporters'] : [];
97 }
98 }
99