UDT to get custom content based on extra content blocks
Posted: Fri Jan 16, 2009 4:59 pm
Hi,
Today I was asked if it is possible to create pages only accessible for some front end users. I said yes because you can.
But I don't want to fix the values for the groups and users in the page content or in a template so this is what I did.
Maybe someone can tell me if this is smart or if there is another way to get it working.
First of all I created a page template for restricted access. Template snippet:
{content assign=pagecontent}
{content block="users" assign="theusers" wysiwyg="false" oneline="true"}
{content block="groups" assign="thegroups" wysiwyg="false" oneline="true"}
In stead of {content} I addes a call to a UDT:
{restricted_to thegroups ="$thegroups" theusers ="$theusers" thepagecontent="$pagecontent"}
Then I wrote a UDT (not complete yet):
$retstr = "";
$groups = FALSE;
$users = FALSE;
if((!isset($params['thegroups']) || empty($params['thegroups'])) && (!isset($params['theusers']) || empty($params['theusers']))){
echo("Enter at least 1 user or group!");
}else{
if( isset($params['thegroups']) && !empty($params['thegroups']) ) {
$groups = explode(';',trim($params['thegroups']));
$result = count($groups);
if($result == 0){
$groups = FALSE;
}
}
if( isset($params['theusers']) && !empty($params['theusers']) ) {
$users = explode(';',trim($params['theusers']));
$result = count($users);
if($result == 0){
$users = FALSE;
}
}
}
global $gCms;
$feusers =& $gCms->modules['FrontEndUsers']['object'];
$userid = $feusers->LoggedInId();
if($userid){
$username = $feusers->LoggedInName();
echo("okay, we we got a user ".$username."");
if($users){
if(in_array($username, $users)){
echo("hi ". $username."");
echo $params['thepagecontent'];
}else{
echo("hi ". $username."");
echo("Not for you");
}
}else{
echo("Hmmm, we have got a user ".$username." but the page doesn't provide users");
}
}else{
echo("Members only!!!");
echo("Login and try again");
}
echo $retstr;
Now I can create pages and select the right template to get the "fields" for users and groups. After entering the username(s) the page is automatically restricted.
I will add the grouppart later on, first I want to know if this is a workable solution...
Cheers,
-- Rob
Today I was asked if it is possible to create pages only accessible for some front end users. I said yes because you can.
But I don't want to fix the values for the groups and users in the page content or in a template so this is what I did.
Maybe someone can tell me if this is smart or if there is another way to get it working.
First of all I created a page template for restricted access. Template snippet:
{content assign=pagecontent}
{content block="users" assign="theusers" wysiwyg="false" oneline="true"}
{content block="groups" assign="thegroups" wysiwyg="false" oneline="true"}
In stead of {content} I addes a call to a UDT:
{restricted_to thegroups ="$thegroups" theusers ="$theusers" thepagecontent="$pagecontent"}
Then I wrote a UDT (not complete yet):
$retstr = "";
$groups = FALSE;
$users = FALSE;
if((!isset($params['thegroups']) || empty($params['thegroups'])) && (!isset($params['theusers']) || empty($params['theusers']))){
echo("Enter at least 1 user or group!");
}else{
if( isset($params['thegroups']) && !empty($params['thegroups']) ) {
$groups = explode(';',trim($params['thegroups']));
$result = count($groups);
if($result == 0){
$groups = FALSE;
}
}
if( isset($params['theusers']) && !empty($params['theusers']) ) {
$users = explode(';',trim($params['theusers']));
$result = count($users);
if($result == 0){
$users = FALSE;
}
}
}
global $gCms;
$feusers =& $gCms->modules['FrontEndUsers']['object'];
$userid = $feusers->LoggedInId();
if($userid){
$username = $feusers->LoggedInName();
echo("okay, we we got a user ".$username."");
if($users){
if(in_array($username, $users)){
echo("hi ". $username."");
echo $params['thepagecontent'];
}else{
echo("hi ". $username."");
echo("Not for you");
}
}else{
echo("Hmmm, we have got a user ".$username." but the page doesn't provide users");
}
}else{
echo("Members only!!!");
echo("Login and try again");
}
echo $retstr;
Now I can create pages and select the right template to get the "fields" for users and groups. After entering the username(s) the page is automatically restricted.
I will add the grouppart later on, first I want to know if this is a workable solution...
Cheers,
-- Rob