| 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 |
namespace UserAccessManager\Controller\Backend; |
| 16 |
|
| 17 |
use UserAccessManager\Controller\Controller; |
| 18 |
|
| 19 |
/** |
| 20 |
* Class AboutController |
| 21 |
* |
| 22 |
* @package UserAccessManager\Controller |
| 23 |
*/ |
| 24 |
class AboutController extends Controller |
| 25 |
{ |
| 26 |
const SUPPORTER_FILE = 'supporters.json'; |
| 27 |
const SUPPORTER_FILE_URL = 'https://gm-alex.github.io/user-access-manager/supporters.json'; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
protected $template = 'AdminAbout.php'; |
| 33 |
|
| 34 |
/** |
| 35 |
* @var null|array |
| 36 |
*/ |
| 37 |
private $supporters = null; |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns all the supporters. |
| 41 |
* |
| 42 |
* @return array |
| 43 |
*/ |
| 44 |
private function getAllSupporters() |
| 45 |
{ |
| 46 |
if ($this->supporters === null) { |
| 47 |
$realPath = rtrim($this->wordpressConfig->getRealPath(), DIRECTORY_SEPARATOR); |
| 48 |
$path = [$realPath, 'assets']; |
| 49 |
$path = implode(DIRECTORY_SEPARATOR, $path).DIRECTORY_SEPARATOR; |
| 50 |
$fileWithPath = $path.self::SUPPORTER_FILE; |
| 51 |
$needsUpdate = is_file($fileWithPath) === false |
| 52 |
|| filemtime($fileWithPath) < $this->wordpress->currentTime('timestamp') - 24 * 60 * 60; |
| 53 |
$fileContent = ($needsUpdate === true) ? @file_get_contents(self::SUPPORTER_FILE_URL) : false; |
| 54 |
|
| 55 |
if ($fileContent !== false) { |
| 56 |
file_put_contents($fileWithPath, $fileContent); |
| 57 |
} elseif (is_file($fileWithPath) === true) { |
| 58 |
$fileContent = file_get_contents($fileWithPath); |
| 59 |
} |
| 60 |
|
| 61 |
$this->supporters = (is_string($fileContent) === true) ? json_decode($fileContent, true) : []; |
| 62 |
} |
| 63 |
|
| 64 |
return $this->supporters; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns the people which earn a special thanks. |
| 69 |
* |
| 70 |
* @return array |
| 71 |
*/ |
| 72 |
public function getSpecialThanks() |
| 73 |
{ |
| 74 |
$supporters = $this->getAllSupporters(); |
| 75 |
return isset($supporters['special-thanks']) === true ? $supporters['special-thanks'] : []; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns the people which earn a special thanks. |
| 80 |
* |
| 81 |
* @return array |
| 82 |
*/ |
| 83 |
public function getTopSupporters() |
| 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 |
* |
| 92 |
* @return array |
| 93 |
*/ |
| 94 |
public function getSupporters() |
| 95 |
{ |
| 96 |
$supporters = $this->getAllSupporters(); |
| 97 |
return isset($supporters['supporters']) === true ? $supporters['supporters'] : []; |
| 98 |
} |
| 99 |
} |
| 100 |
|