| @@ -11,11 +11,8 @@ | ||
| 11 | 11 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 | 12 | * @version SVN: $id$ |
| 13 | 13 | * @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 | 14 | */ |
| 15 | - | |
| 16 | -declare(strict_types=1); | |
| 17 | - | |
| 18 | 15 | namespace UserAccessManager\Controller\Frontend; |
| 19 | 16 | |
| 20 | 17 | use UserAccessManager\Access\AccessHandler; |
| 21 | 18 | use UserAccessManager\Config\MainConfig; |
| @@ -21,9 +18,8 @@ | ||
| 21 | 18 | use UserAccessManager\Config\MainConfig; |
| 22 | 19 | use UserAccessManager\Config\WordpressConfig; |
| 23 | 20 | use UserAccessManager\Controller\Controller; |
| 24 | 21 | use UserAccessManager\UserAccessManager; |
| 25 | -use UserAccessManager\UserGroup\UserGroupTypeException; | |
| 26 | 22 | use UserAccessManager\Wrapper\Php; |
| 27 | 23 | use UserAccessManager\Wrapper\Wordpress; |
| 28 | 24 | |
| 29 | 25 | /** |
| @@ -32,21 +28,49 @@ | ||
| 32 | 28 | * @package UserAccessManager\Controller |
| 33 | 29 | */ |
| 34 | 30 | class FrontendController extends Controller |
| 35 | 31 | { |
| 36 | - public const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 32 | + const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 37 | 33 | |
| 34 | + /** | |
| 35 | + * @var MainConfig | |
| 36 | + */ | |
| 37 | + private $mainConfig; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @var AccessHandler | |
| 41 | + */ | |
| 42 | + private $accessHandler; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * FrontendController constructor. | |
| 46 | + * | |
| 47 | + * @param Php $php | |
| 48 | + * @param Wordpress $wordpress | |
| 49 | + * @param WordpressConfig $wordpressConfig | |
| 50 | + * @param MainConfig $mainConfig | |
| 51 | + * @param AccessHandler $userHandler | |
| 52 | + */ | |
| 38 | 53 | public function __construct( |
| 39 | 54 | Php $php, |
| 40 | 55 | Wordpress $wordpress, |
| 41 | 56 | WordpressConfig $wordpressConfig, |
| 42 | - private MainConfig $mainConfig, | |
| 43 | - private AccessHandler $accessHandler | |
| 57 | + MainConfig $mainConfig, | |
| 58 | + AccessHandler $userHandler | |
| 44 | 59 | ) { |
| 45 | 60 | parent::__construct($php, $wordpress, $wordpressConfig); |
| 61 | + $this->mainConfig = $mainConfig; | |
| 62 | + $this->accessHandler = $userHandler; | |
| 46 | 63 | } |
| 47 | 64 | |
| 48 | - private function registerStylesAndScripts(): void | |
| 65 | + /** | |
| 66 | + * Functions for other content. | |
| 67 | + */ | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Register all other styles. | |
| 71 | + */ | |
| 72 | + private function registerStylesAndScripts() | |
| 49 | 73 | { |
| 50 | 74 | $urlPath = $this->wordpressConfig->getUrlPath(); |
| 51 | 75 | |
| 52 | 76 | $this->wordpress->registerStyle( |
| @@ -57,9 +81,12 @@ | ||
| 57 | 81 | 'screen' |
| 58 | 82 | ); |
| 59 | 83 | } |
| 60 | 84 | |
| 61 | - public function enqueueStylesAndScripts(): void | |
| 85 | + /** | |
| 86 | + * The function for the wp_enqueue_scripts action. | |
| 87 | + */ | |
| 88 | + public function enqueueStylesAndScripts() | |
| 62 | 89 | { |
| 63 | 90 | $this->registerStylesAndScripts(); |
| 64 | 91 | $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM); |
| 65 | 92 | } |
| @@ -64,11 +91,17 @@ | ||
| 64 | 91 | $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM); |
| 65 | 92 | } |
| 66 | 93 | |
| 67 | 94 | /** |
| 68 | - * @throws UserGroupTypeException | |
| 95 | + * The function for the get_ancestors filter. | |
| 96 | + * | |
| 97 | + * @param array $ancestors | |
| 98 | + * @param int $objectId | |
| 99 | + * @param string $objectType | |
| 100 | + * | |
| 101 | + * @return array | |
| 69 | 102 | */ |
| 70 | - public function showAncestors(array $ancestors, int|string|null $objectId, string $objectType): array | |
| 103 | + public function showAncestors($ancestors, $objectId, $objectType) | |
| 71 | 104 | { |
| 72 | 105 | if ($this->mainConfig->lockRecursive() === true |
| 73 | 106 | && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false |
| 74 | 107 | ) { |
| @@ -89,30 +122,19 @@ | ||
| 89 | 122 | * Functions for the redirection and files. |
| 90 | 123 | */ |
| 91 | 124 | |
| 92 | 125 | /** |
| 93 | - * @throws UserGroupTypeException | |
| 126 | + * Filter for Yoast SEO Plugin | |
| 127 | + * | |
| 128 | + * Hides the url from the site map if the user has no access | |
| 129 | + * | |
| 130 | + * @param string $url The url to check | |
| 131 | + * @param string $type The object type | |
| 132 | + * @param object $object The object | |
| 133 | + * | |
| 134 | + * @return false|string | |
| 94 | 135 | */ |
| 95 | - public function getWpSeoUrl(array|string $url, string $type, object $object): bool|array|string | |
| 136 | + public function getWpSeoUrl($url, $type, $object) | |
| 96 | 137 | { |
| 97 | 138 | return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false; |
| 98 | - } | |
| 99 | - | |
| 100 | - /* | |
| 101 | - * Elementor | |
| 102 | - */ | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * @throws UserGroupTypeException | |
| 106 | - */ | |
| 107 | - public function getElementorContent($content): mixed | |
| 108 | - { | |
| 109 | - $this->wordpress->removeAction('elementor/frontend/the_content', [$this, 'getElementorContent']); | |
| 110 | - $post = $this->wordpress->getCurrentPost(); | |
| 111 | - | |
| 112 | - if ($this->accessHandler->checkObjectAccess($post->post_type, $post->ID) === false) { | |
| 113 | - $content = htmlspecialchars_decode($this->mainConfig->getPostTypeContent($post->post_type)); | |
| 114 | - } | |
| 115 | - | |
| 116 | - return $content; | |
| 117 | 139 | } |
| 118 | 140 | } |