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