assign(trim($params['assign_error_id']),$errorid);}
if (isset($params['assign_error'])){$smarty->assign(trim($params['assign_error']),$error);}
}
}
// lets start by setting some defaults
$errorid = 0;
$error = 'Apparantly no errors';
$extra='';
$result = '';
if (!isset( $params['expired']))
{
$params['show_expired'] = FALSE;
}
if (!isset( $params['properties']))
{
$errorid = 1;
$error = 'Properties parameter MUST be set!';
jm_errors($errorid, $error, $smarty, $params);
return;
}
// we have properties
$properties = array_map('trim',explode(",",$params['properties']));
$gCms = cmsms();
$conf = $gCms->GetConfig();
$feu = cms_utils::get_module('FrontEndUsers');
if (!$feu)
{
$errorid = 2;
$error = 'Cannot connect to FrontEndUsers module!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
// we have FEU Module
if (isset($params['uid'])) // use ID
{
$uid = $params['uid'];
$username = $feu->GetUserName($uid);
if (!$username)
{
$errorid = 4;
$error = 'User not found!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
elseif (isset($params['username'])) // use Username
{
$username = trim($params['username']);
$uid = $feu->GetUserID($username);
if (!$uid)
{
$errorid = 4;
$error = 'User not found!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
else // use URL
{
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
$curcontent =& $currentNode->GetContent();
$extra = str_replace($conf['page_extension'],'', ($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
$extra = preg_replace('%/\z|' . $conf['page_extension'] . '\z%', '', $extra);
$filter = str_replace('http://','',str_replace($conf['page_extension'],'', $curcontent->getURL()));
$extra = str_replace($filter . '/', '', $extra);
$extra = explode('/',$extra);
$username = $extra[0];
if (empty($username)) // the triage failed to produce a username or userid
{
$errorid = 3;
$error = 'Unable to extract a username or user id to compute!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
# we have an ID
$uid = $feu->GetUserID($username);
if (!$uid)
{
$errorid = 4;
$error = 'User not found!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
if (isset($params['feu_group']))
{
if (!$feu->GroupExistsByName($params['feu_group']))
{
$errorid = 6;
$error = 'Group does not exist!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
// group exists
$gid = $feu->GetGroupID(trim($params['feu_group']));
if (!$feu->MemberOfGroup($uid, $gid))
{
$errorid = 7;
$error = 'User does not belong to this group!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
// cleared from group triage -> carry on!
// now let's check for expired user
if ($feu->IsAccountExpired($uid) && (!$params['show_expired']))
{
$errorid = 5;
$error = 'This user account has expired!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
if (isset($params['if_property']))
{
if (!isset($params['if_value']))
{
$errorid = 8;
$error = 'When using if_property if_value must be used!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
else
{
$params['if_property'] = ''; # this should take care of the bug #9891
}
$feuproperties = $feu->GetUserProperties($uid);
foreach($properties as $property)
{
foreach($feuproperties as $key=>$value)
{
if (($value["title"] == trim($params['if_property'])))
{
if (!($value['data'] == trim($params['if_value'])))
{
unset($result);
$errorid = 9;
$error = 'if_property does not match if_value!';
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
}
if ($value["title"] == trim($property))
{
$result[$value["title"]] = $value['data'];
}
}
} // foreach($properties as $property) <- end
if (isset($params['assign_result']))
{
$smarty->assign(trim($params['assign_result']),$result);
jm_feu_errors($errorid, $error, $smarty, $params);
return;
}
jm_feu_errors($errorid, $error, $smarty, $params);
return implode('
', $result);
}
function smarty_cms_help_function_jm_feu_user_props()
{
?>
This tag retrieves properties from FEU Module.
The idea is to be able to retrieve an array filled with properties, and use them
anywere needed in a template or content block.
One of the objectives was to be able to give my FE users the ability to have a
small page of their own, accessible through an unique URL they could give to their
potencial visitors:
http://www.yourdomain.com/usergroup/username.html
or
http://www.yourdomain.com/users/username.html
This does not replace CGUserDirectory, but doesn't require it.
It has a different purpose than the CGUserDirectory module.
This plugin requires FEU module, and is meant to be used with Pretty URL's
and the following configuration:
$config['url_rewriting'] = 'mod_rewrite';
This is a basic example of how to use it:
Insert tag {jm_feu_user_props [parameters]}
in your Content textarea, Smarty data or logic that is specific to this page textarea, or template:
{jm_feu_user_props properties='somefeuproperty1,somefeuproperty2,somefeuproperty3,...,somefeuproperty_n'}
This will return the following result:
somefeuproperty1<br />somefeuproperty2<br />somefeuproperty3<br />...<br />somefeuproperty_n<br />
Not very usable but that's the basic...
Advanced use of this tag assumes that you pass some variable names to assign the different results:
{jm_feu_user_props properties='feuprop1,feuprop2,somefeuprop3'
assign_error_id='userprops_error_id' assign_result='user_props'
feu_group='feu_group' if_property='feuprop4' if_value='somevalue'}
This more advanced use has almost all parameters filled. The expected result are as follows:
assign_result='user_props': with this parameter set the plugin goes into silent mode,
meaning that the smarty variable user_props will hold an array with the values of the properties you wanted:
user_props array(4){
["feuprop1"]=> "value1"
["feuprop2"]=> "value2"
["feuprop3"]=> "value3"
}
So you can access them in your template like this:
{$user_props.feuprop1}
{$user_props.feuprop2}
{$user_props.feuprop3}
OK, so where is the username coming from?
from: http://www.yourdomain.com/usergroup/username.html
or even: http://www.yourdomain.com/usergroup/username/
By default the username is captured from the URL, except when the parameters username or uid are used.
These override by priorities: uid overrides username which in turn overrides the URL capture.
Also, in the previous example you get this:
a) if the user doesn't belong to feu_group='feu_group' the properties array is NULL;
b) if the if_property='somefeuprop' value doesn't match the
if_value='somevalue' the properties array is NULL;
c) if you use if_property='somefeuprop', you MUST use
if_value='somevalue' otherwise the properties array is NULL no matter what;
d) The plugin generates error codes, assign to assign_error_id='userprops_error_id'
giving you the chance to use some if...then...else logic with Smarty
Although you can use the plugin tag inside your template or content block, it makes sense if you use it inside the Smarty data or logic that is specific to this page textarea as it enables you to use any of the variables (the one, for instance, that holds the full User Name or the 1st and last names) in the Page title.
Errors and Error Codes
Error Code - Explanation
0 - No error;
1 - properties parameter MUST be set!
2 - Cannot connect to FrontEndUsers module!
3 - Unable to extract a username or user id to compute!
4 - User not found!
5 - This user account has expired!
6 - Group does not exist!
7 - User does not belong to this group!
8 - When using if_property, if_value must be used!
9 - if_property does not match if_value!
Author: Fernando Morgado (JoMorg)
Version: 1.0.1
Change History: