Skip to content

Instantly share code, notes, and snippets.

@ursbraem
Forked from lorenzulrich/Condition.php
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursbraem/a407c204e3bc2c939964 to your computer and use it in GitHub Desktop.
Save ursbraem/a407c204e3bc2c939964 to your computer and use it in GitHub Desktop.
namespace My\Site\Userfunc;
/**
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
class Condition {
/**
* Custom condition to check if the current page has access-restricted content elements
*
* Usage in TypoScript:
* [userFunc = My\Site\Userfunc\Condition::pageHasRestrictedContent()]
*
* @return bool
*/
public function pageHasRestrictedContent() {
// get pid
$pid = $GLOBALS['TSFE']->id;
// get array of all usergroups of logged in user
// does this return all, and as an array?
$loggedInGroups = $GLOBALS['TSFE']->fe_user->user[usergroup];
// get array of all CE uids on page
// should I use $GLOBALS['TYPO3_DB']->exec_SELECTquery and loop through it with $GLOBALS['TYPO3_DB']->sql_num_rows afterwards?
// Or something else?
// And do I have to pass "not hidden, not deleted, not expired" manually?
$cEs = xxx
// loop through all content elements
foreach ($cEs as $cE) {
// get array of all group IDs for that CE
// same question as above: how to fetch them properly?
$cEGroups = xxx
foreach ($cEGroups as $cEGroup){
// if this element has a fe_groups restriction, but the currently logged in user doesn't belong to at least one of those groups, we have a match: there is content on the page the user can't access
if (!empty($cEGroup) && !array_key_exists($cEGroup, $loggedInGroups)) {
return TRUE;
}
}
}
return FALSE;
}
}
@ursbraem
Copy link
Author

ursbraem commented Jul 6, 2015

Supposing one person can only have one fe user, the function could return false already after detecting a logged in fe user: no need to display a login form.

@ursbraem
Copy link
Author

ursbraem commented Jul 6, 2015

Then again, all that detecting loggedInGroups is unneccessary too.. aaah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment