| 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 |
*/ |
| 15 |
namespace UserAccessManager\Controller\Frontend; |
| 16 |
|
| 17 |
use UserAccessManager\Access\AccessHandler; |
| 18 |
use UserAccessManager\Config\MainConfig; |
| 19 |
use UserAccessManager\Config\WordpressConfig; |
| 20 |
use UserAccessManager\Controller\Controller; |
| 21 |
use UserAccessManager\UserAccessManager; |
| 22 |
use UserAccessManager\Wrapper\Php; |
| 23 |
use UserAccessManager\Wrapper\Wordpress; |
| 24 |
|
| 25 |
/** |
| 26 |
* Class FrontendController |
| 27 |
* |
| 28 |
* @package UserAccessManager\Controller |
| 29 |
*/ |
| 30 |
class FrontendController extends Controller |
| 31 |
{ |
| 32 |
const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm'; |
| 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 |
*/ |
| 53 |
public function __construct( |
| 54 |
Php $php, |
| 55 |
Wordpress $wordpress, |
| 56 |
WordpressConfig $wordpressConfig, |
| 57 |
MainConfig $mainConfig, |
| 58 |
AccessHandler $userHandler |
| 59 |
) { |
| 60 |
parent::__construct($php, $wordpress, $wordpressConfig); |
| 61 |
$this->mainConfig = $mainConfig; |
| 62 |
$this->accessHandler = $userHandler; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Functions for other content. |
| 67 |
*/ |
| 68 |
|
| 69 |
/** |
| 70 |
* Register all other styles. |
| 71 |
*/ |
| 72 |
private function registerStylesAndScripts() |
| 73 |
{ |
| 74 |
$urlPath = $this->wordpressConfig->getUrlPath(); |
| 75 |
|
| 76 |
$this->wordpress->registerStyle( |
| 77 |
self::HANDLE_STYLE_LOGIN_FORM, |
| 78 |
$urlPath.'assets/css/uamLoginForm.css', |
| 79 |
[], |
| 80 |
UserAccessManager::VERSION, |
| 81 |
'screen' |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* The function for the wp_enqueue_scripts action. |
| 87 |
*/ |
| 88 |
public function enqueueStylesAndScripts() |
| 89 |
{ |
| 90 |
$this->registerStylesAndScripts(); |
| 91 |
$this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 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 |
| 102 |
*/ |
| 103 |
public function showAncestors($ancestors, $objectId, $objectType) |
| 104 |
{ |
| 105 |
if ($this->mainConfig->lockRecursive() === true |
| 106 |
&& $this->accessHandler->checkObjectAccess($objectType, $objectId) === false |
| 107 |
) { |
| 108 |
return []; |
| 109 |
} |
| 110 |
|
| 111 |
foreach ($ancestors as $key => $ancestorId) { |
| 112 |
if ($this->accessHandler->checkObjectAccess($objectType, $ancestorId) === false) { |
| 113 |
unset($ancestors[$key]); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
return $ancestors; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/* |
| 122 |
* Functions for the redirection and files. |
| 123 |
*/ |
| 124 |
|
| 125 |
/** |
| 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 |
| 135 |
*/ |
| 136 |
public function getWpSeoUrl($url, $type, $object) |
| 137 |
{ |
| 138 |
return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false; |
| 139 |
} |
| 140 |
} |
| 141 |
|