| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\Controller\Frontend\Content; |
| 6 |
|
| 7 |
use UserAccessManager\Config\MainConfig; |
| 8 |
use UserAccessManager\Config\WordpressConfig; |
| 9 |
use UserAccessManager\User\UserHandler; |
| 10 |
use UserAccessManager\UserGroup\UserGroupHandler; |
| 11 |
use UserAccessManager\UserGroup\UserGroupTypeException; |
| 12 |
use UserAccessManager\Util\Util; |
| 13 |
use UserAccessManager\Wrapper\Wordpress; |
| 14 |
|
| 15 |
trait AdminOutputControllerTrait |
| 16 |
{ |
| 17 |
abstract protected function getWordpress(): Wordpress; |
| 18 |
abstract protected function getWordpressConfig(): WordpressConfig; |
| 19 |
abstract protected function getMainConfig(): MainConfig; |
| 20 |
abstract protected function getUtil(): Util; |
| 21 |
abstract protected function getUserHandler(): UserHandler; |
| 22 |
abstract protected function getUserGroupHandler(): UserGroupHandler; |
| 23 |
|
| 24 |
private function showAdminHint(): bool |
| 25 |
{ |
| 26 |
return $this->getWordpressConfig()->atAdminPanel() === false |
| 27 |
&& $this->getMainConfig()->blogAdminHint() === true; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @throws UserGroupTypeException |
| 32 |
*/ |
| 33 |
public function adminOutput(string $objectType, int|string|null $objectId, $text = null): string |
| 34 |
{ |
| 35 |
if ($this->showAdminHint() === true) { |
| 36 |
$hintText = $this->getMainConfig()->getBlogAdminHintText(); |
| 37 |
|
| 38 |
if ($text !== null && $this->getUtil()->endsWith($text, $hintText) === true) { |
| 39 |
return ''; |
| 40 |
} |
| 41 |
|
| 42 |
if ($this->getUserHandler()->userIsAdmin($this->getWordpress()->getCurrentUser()->ID) === true |
| 43 |
&& count($this->getUserGroupHandler()->getUserGroupsForObject($objectType, $objectId)) > 0 |
| 44 |
) { |
| 45 |
return $hintText; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return ''; |
| 50 |
} |
| 51 |
} |
| 52 |
|