| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * ShortCodeController.php | |
| 4 | + * | |
| 5 | + * The ShortCodeController 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 | + */ | |
| 2 | 15 | |
| 3 | 16 | declare(strict_types=1); |
| 4 | 17 | |
| 5 | 18 | namespace UserAccessManager\Controller\Frontend; |
| @@ -10,26 +23,51 @@ | ||
| 10 | 23 | use UserAccessManager\UserGroup\UserGroupTypeException; |
| 11 | 24 | use UserAccessManager\Wrapper\Php; |
| 12 | 25 | use UserAccessManager\Wrapper\Wordpress; |
| 13 | 26 | |
| 27 | +/** | |
| 28 | + * Class ShortCodeController | |
| 29 | + * | |
| 30 | + * @package UserAccessManager\Controller\Frontend | |
| 31 | + */ | |
| 14 | 32 | class ShortCodeController extends Controller |
| 15 | 33 | { |
| 16 | 34 | use LoginControllerTrait; |
| 17 | 35 | |
| 36 | + /** | |
| 37 | + * @var UserGroupHandler | |
| 38 | + */ | |
| 39 | + protected $userGroupHandler; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * ShortCodeController constructor. | |
| 43 | + * @param Php $php | |
| 44 | + * @param Wordpress $wordpress | |
| 45 | + * @param WordpressConfig $wordpressConfig | |
| 46 | + * @param UserGroupHandler $userGroupHandler | |
| 47 | + */ | |
| 18 | 48 | public function __construct( |
| 19 | 49 | Php $php, |
| 20 | 50 | Wordpress $wordpress, |
| 21 | 51 | WordpressConfig $wordpressConfig, |
| 22 | - protected UserGroupHandler $userGroupHandler | |
| 52 | + UserGroupHandler $userGroupHandler | |
| 23 | 53 | ) { |
| 24 | 54 | parent::__construct($php, $wordpress, $wordpressConfig); |
| 55 | + $this->userGroupHandler = $userGroupHandler; | |
| 25 | 56 | } |
| 26 | 57 | |
| 58 | + /** | |
| 59 | + * @return Wordpress | |
| 60 | + */ | |
| 27 | 61 | protected function getWordpress(): Wordpress |
| 28 | 62 | { |
| 29 | 63 | return $this->wordpress; |
| 30 | 64 | } |
| 31 | 65 | |
| 66 | + /** | |
| 67 | + * Returns the login bar. | |
| 68 | + * @return string | |
| 69 | + */ | |
| 32 | 70 | public function getLoginFormHtml(): string |
| 33 | 71 | { |
| 34 | 72 | $loginForm = ''; |
| 35 | 73 | |
| @@ -39,28 +77,47 @@ | ||
| 39 | 77 | |
| 40 | 78 | return $this->wordpress->applyFilters('uam_login_form', $loginForm); |
| 41 | 79 | } |
| 42 | 80 | |
| 81 | + /** | |
| 82 | + * Handles the login form short code. | |
| 83 | + * @return string | |
| 84 | + */ | |
| 43 | 85 | public function loginFormShortCode(): string |
| 44 | 86 | { |
| 45 | 87 | return $this->getLoginFormHtml(); |
| 46 | 88 | } |
| 47 | 89 | |
| 48 | - public function publicShortCode(mixed $attributes, string $content = ''): string | |
| 90 | + /** | |
| 91 | + * Handles the public short code. | |
| 92 | + * @param string|array $attributes | |
| 93 | + * @param string $content | |
| 94 | + * @return string | |
| 95 | + */ | |
| 96 | + public function publicShortCode($attributes, $content = ''): string | |
| 49 | 97 | { |
| 50 | 98 | return ($this->wordpress->isUserLoggedIn() === false) ? $this->wordpress->doShortCode($content) : ''; |
| 51 | 99 | } |
| 52 | 100 | |
| 101 | + /** | |
| 102 | + * Returns the user group map from the short code attribute. | |
| 103 | + * @param array $attributes | |
| 104 | + * @return array | |
| 105 | + */ | |
| 53 | 106 | private function getUserGroupsMapFromAttributes(array $attributes): array |
| 54 | 107 | { |
| 55 | 108 | $userGroups = (isset($attributes['group']) === true) ? explode(',', $attributes['group']) : []; |
| 56 | - return array_flip(array_map('trim', $userGroups)); | |
| 109 | + return (array) array_flip(array_map('trim', $userGroups)); | |
| 57 | 110 | } |
| 58 | 111 | |
| 59 | 112 | /** |
| 113 | + * Handles the private short code. | |
| 114 | + * @param array $attributes | |
| 115 | + * @param string $content | |
| 116 | + * @return string | |
| 60 | 117 | * @throws UserGroupTypeException |
| 61 | 118 | */ |
| 62 | - public function privateShortCode(array $attributes, string $content = ''): string | |
| 119 | + public function privateShortCode(array $attributes, $content = ''): string | |
| 63 | 120 | { |
| 64 | 121 | if ($this->wordpress->isUserLoggedIn() === true) { |
| 65 | 122 | $userGroupMap = $this->getUserGroupsMapFromAttributes($attributes); |
| 66 | 123 | |