| @@ -1,8 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 2 | +/** | |
| 3 | + * FrontendController.php | |
| 4 | + * | |
| 5 | + * The FrontendController 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\Access\AccessHandler; |
| 8 | 18 | use UserAccessManager\Config\MainConfig; |
| @@ -8,42 +18,90 @@ | ||
| 8 | 18 | use UserAccessManager\Config\MainConfig; |
| 9 | 19 | use UserAccessManager\Config\WordpressConfig; |
| 10 | 20 | use UserAccessManager\Controller\Controller; |
| 11 | 21 | use UserAccessManager\UserAccessManager; |
| 12 | -use UserAccessManager\UserGroup\UserGroupTypeException; | |
| 13 | 22 | use UserAccessManager\Wrapper\Php; |
| 14 | 23 | use UserAccessManager\Wrapper\Wordpress; |
| 15 | 24 | |
| 25 | +/** | |
| 26 | + * Class FrontendController | |
| 27 | + * | |
| 28 | + * @package UserAccessManager\Controller | |
| 29 | + */ | |
| 16 | 30 | class FrontendController extends Controller |
| 17 | 31 | { |
| 18 | - public const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 32 | + const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 19 | 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 | + */ | |
| 20 | 53 | public function __construct( |
| 21 | 54 | Php $php, |
| 22 | 55 | Wordpress $wordpress, |
| 23 | 56 | WordpressConfig $wordpressConfig, |
| 24 | - private MainConfig $mainConfig, | |
| 25 | - private AccessHandler $accessHandler | |
| 57 | + MainConfig $mainConfig, | |
| 58 | + AccessHandler $userHandler | |
| 26 | 59 | ) { |
| 27 | 60 | parent::__construct($php, $wordpress, $wordpressConfig); |
| 61 | + $this->mainConfig = $mainConfig; | |
| 62 | + $this->accessHandler = $userHandler; | |
| 28 | 63 | } |
| 29 | 64 | |
| 30 | - public function enqueueStylesAndScripts(): void | |
| 65 | + /** | |
| 66 | + * Functions for other content. | |
| 67 | + */ | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Register all other styles. | |
| 71 | + */ | |
| 72 | + private function registerStylesAndScripts() | |
| 31 | 73 | { |
| 74 | + $urlPath = $this->wordpressConfig->getUrlPath(); | |
| 75 | + | |
| 32 | 76 | $this->wordpress->registerStyle( |
| 33 | 77 | self::HANDLE_STYLE_LOGIN_FORM, |
| 34 | - $this->wordpressConfig->getUrlPath().'assets/css/uamLoginForm.css', | |
| 78 | + $urlPath.'assets/css/uamLoginForm.css', | |
| 35 | 79 | [], |
| 36 | 80 | UserAccessManager::VERSION, |
| 37 | 81 | 'screen' |
| 38 | 82 | ); |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * The function for the wp_enqueue_scripts action. | |
| 87 | + */ | |
| 88 | + public function enqueueStylesAndScripts() | |
| 89 | + { | |
| 90 | + $this->registerStylesAndScripts(); | |
| 39 | 91 | $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM); |
| 40 | 92 | } |
| 41 | 93 | |
| 42 | 94 | /** |
| 43 | - * @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 | |
| 44 | 102 | */ |
| 45 | - public function showAncestors(array $ancestors, int|string|null $objectId, string $objectType): array | |
| 103 | + public function showAncestors($ancestors, $objectId, $objectType) | |
| 46 | 104 | { |
| 47 | 105 | if ($this->mainConfig->lockRecursive() === true |
| 48 | 106 | && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false |
| 49 | 107 | ) { |
| @@ -58,27 +116,25 @@ | ||
| 58 | 116 | |
| 59 | 117 | return $ancestors; |
| 60 | 118 | } |
| 61 | 119 | |
| 62 | - /** | |
| 63 | - * @throws UserGroupTypeException | |
| 120 | + | |
| 121 | + /* | |
| 122 | + * Functions for the redirection and files. | |
| 64 | 123 | */ |
| 65 | - public function getWpSeoUrl(array|string $url, string $type, object $object): bool|array|string | |
| 66 | - { | |
| 67 | - return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false; | |
| 68 | - } | |
| 69 | 124 | |
| 70 | 125 | /** |
| 71 | - * @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 | |
| 72 | 135 | */ |
| 73 | - public function getElementorContent(mixed $content): mixed | |
| 136 | + public function getWpSeoUrl($url, $type, $object) | |
| 74 | 137 | { |
| 75 | - $this->wordpress->removeAction('elementor/frontend/the_content', [$this, 'getElementorContent']); | |
| 76 | - $post = $this->wordpress->getCurrentPost(); | |
| 77 | - | |
| 78 | - if ($this->accessHandler->checkObjectAccess($post->post_type, $post->ID) === false) { | |
| 79 | - $content = htmlspecialchars_decode($this->mainConfig->getPostTypeContent($post->post_type)); | |
| 80 | - } | |
| 81 | - | |
| 82 | - return $content; | |
| 138 | + return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false; | |
| 83 | 139 | } |
| 84 | 140 | } |