| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * FrontendController.php | |
| 4 | + * | |
| 5 | + * The FrontendController 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; |
| @@ -12,38 +25,85 @@ | ||
| 12 | 25 | use UserAccessManager\UserGroup\UserGroupTypeException; |
| 13 | 26 | use UserAccessManager\Wrapper\Php; |
| 14 | 27 | use UserAccessManager\Wrapper\Wordpress; |
| 15 | 28 | |
| 29 | +/** | |
| 30 | + * Class FrontendController | |
| 31 | + * | |
| 32 | + * @package UserAccessManager\Controller | |
| 33 | + */ | |
| 16 | 34 | class FrontendController extends Controller |
| 17 | 35 | { |
| 18 | - public const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 36 | + const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; | |
| 19 | 37 | |
| 38 | + /** | |
| 39 | + * @var MainConfig | |
| 40 | + */ | |
| 41 | + private $mainConfig; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @var AccessHandler | |
| 45 | + */ | |
| 46 | + private $accessHandler; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * FrontendController constructor. | |
| 50 | + * @param Php $php | |
| 51 | + * @param Wordpress $wordpress | |
| 52 | + * @param WordpressConfig $wordpressConfig | |
| 53 | + * @param MainConfig $mainConfig | |
| 54 | + * @param AccessHandler $userHandler | |
| 55 | + */ | |
| 20 | 56 | public function __construct( |
| 21 | 57 | Php $php, |
| 22 | 58 | Wordpress $wordpress, |
| 23 | 59 | WordpressConfig $wordpressConfig, |
| 24 | - private MainConfig $mainConfig, | |
| 25 | - private AccessHandler $accessHandler | |
| 60 | + MainConfig $mainConfig, | |
| 61 | + AccessHandler $userHandler | |
| 26 | 62 | ) { |
| 27 | 63 | parent::__construct($php, $wordpress, $wordpressConfig); |
| 64 | + $this->mainConfig = $mainConfig; | |
| 65 | + $this->accessHandler = $userHandler; | |
| 28 | 66 | } |
| 29 | 67 | |
| 30 | - public function enqueueStylesAndScripts(): void | |
| 68 | + /** | |
| 69 | + * Functions for other content. | |
| 70 | + */ | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Register all other styles. | |
| 74 | + */ | |
| 75 | + private function registerStylesAndScripts() | |
| 31 | 76 | { |
| 77 | + $urlPath = $this->wordpressConfig->getUrlPath(); | |
| 78 | + | |
| 32 | 79 | $this->wordpress->registerStyle( |
| 33 | 80 | self::HANDLE_STYLE_LOGIN_FORM, |
| 34 | - $this->wordpressConfig->getUrlPath().'assets/css/uamLoginForm.css', | |
| 81 | + $urlPath.'assets/css/uamLoginForm.css', | |
| 35 | 82 | [], |
| 36 | 83 | UserAccessManager::VERSION, |
| 37 | 84 | 'screen' |
| 38 | 85 | ); |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * The function for the wp_enqueue_scripts action. | |
| 90 | + */ | |
| 91 | + public function enqueueStylesAndScripts() | |
| 92 | + { | |
| 93 | + $this->registerStylesAndScripts(); | |
| 39 | 94 | $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM); |
| 40 | 95 | } |
| 41 | 96 | |
| 42 | 97 | /** |
| 98 | + * The function for the get_ancestors filter. | |
| 99 | + * @param array $ancestors | |
| 100 | + * @param int|string $objectId | |
| 101 | + * @param string $objectType | |
| 102 | + * @return array | |
| 43 | 103 | * @throws UserGroupTypeException |
| 44 | 104 | */ |
| 45 | - public function showAncestors(array $ancestors, int|string|null $objectId, string $objectType): array | |
| 105 | + public function showAncestors(array $ancestors, $objectId, string $objectType): array | |
| 46 | 106 | { |
| 47 | 107 | if ($this->mainConfig->lockRecursive() === true |
| 48 | 108 | && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false |
| 49 | 109 | ) { |
| @@ -58,27 +118,23 @@ | ||
| 58 | 118 | |
| 59 | 119 | return $ancestors; |
| 60 | 120 | } |
| 61 | 121 | |
| 62 | - /** | |
| 63 | - * @throws UserGroupTypeException | |
| 122 | + | |
| 123 | + /* | |
| 124 | + * Functions for the redirection and files. | |
| 64 | 125 | */ |
| 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 | 126 | |
| 70 | 127 | /** |
| 128 | + * Filter for Yoast SEO Plugin | |
| 129 | + * Hides the url from the site map if the user has no access | |
| 130 | + * @param string|array $url The url to check | |
| 131 | + * @param string $type The object type | |
| 132 | + * @param object $object The object | |
| 133 | + * @return false|string | |
| 71 | 134 | * @throws UserGroupTypeException |
| 72 | 135 | */ |
| 73 | - public function getElementorContent(mixed $content): mixed | |
| 136 | + public function getWpSeoUrl($url, string $type, object $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 | } |