I'm can code very efficiently in pascal/delphi and have been slowly learning php mainly out of need. Actually CMSMS helped me a good bit. I've also published 2 plugins, one as my "Hello world!" to both PHP and CMSMS contribution, the other out of need.
Now (again out of need) I'm trying a new one.
Here's the problem:
Two years ago I found a post on these forums that I can't find, and that basically almost solved my problem. As I can't find it, and this time I needed to go a bit further I thought about this way of doing it.
What I needed was to be able to have a page for certain FEU groups (one for each), in which I could base FEU pages (for allowed groups of users) so that each user was responsible for its own page contents.
The other part of the problem was that I needed to be able to have the front end being accessed by a pretty URL like:
Code: Select all
www.domain.com/<usergroup>/<username>.html
Code: Select all
{if isset($feu_edit_mode)}
{if $feu_edit_mode == "1"}
{* if this is EditDataMode 1 then .... *}
{global_content name='User_Default_ChangeSettingsTemplate'}
{/if}{* My Control mode 1 END *}
{/if}{* My Control isset($feu_edit_mode *}
The second part of the problem was not so easy... I thought about solving it with an UDT but ended up writing a plugin for this purpose.
As I have set the Page URL of each group page to the name of the group, I only needed a Tag to get a user properties based on the parameters passed on the URL.
I took a look at the get_user_props UDT (I think that´s the name...) but it was not exactly what I needed, so I came up with this:
Code: Select all
/**
* the input parameters are:
*
* - properties: the properties you want to get from FEU coma separated; REQUIRED!
* - username: the username you want to get the properties from; Optional.
* - uid: the user id you want to get the properties from; Optional.
*
* (you can set one or the other or none, in which case the plugin tries to
* extract the username from the $_GET array. The plugin will work by priorities:
* 1st- uid, 2nd- username, 3rd- $_GET array)
* - show_expired: default FALSE; Optional - set if you need to show expired accounts.
* - feu_group: filter user by group; Optional
* - if_property: use a FEU property to check for a value; Optional.
* - if_value: value of the if_property to compare to; REQUIRED if the if_property is set.
* - assign_error: if set you can get a message describing the error; Optional - for debug purposes!
* - assign_error_id: if set you can get an error code (integer) and act on it; Optional - use assign_error to understand the error code;
* - assign_result: should be set to get the result as an array. Optional......
* However ... (todo - explain better)
*
* @param mixed $params
* @param mixed $smarty
*/
function smarty_cms_function_jm_feu_user_props( $params, &$smarty )
{
//helper - error function
if (!function_exists(jm_errors))
{
function jm_errors($eid, $er)
{
if (isset($params['assign_error'])){$smarty->assign(trim($params['assign_error']),$er);}
if (isset($params['assign_error_id'])){$smarty->assign(trim($params['assign_error_id']),$eid);}
}
}
// lets start by setting some defaults
$errorid = 0;
$error = '';
$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);
return;
}
// we have properties
$properties = explode(',', $params['properties']);
$gCms = cmsms();
$feu = cms_utils::get_module('FrontEndUsers');
if (!$feu)
{
$errorid = 2;
$error = 'Cannot connect to FrontEndUsers module!';
jm_errors($errorid, $error);
return;
}
// we have FEU Module
$conf = $gCms->GetConfig();
if (isset($params['uid'])) // use ID
{
$uid = $params['uid'];
$username = $feu->GetUserName($uid);
}
elseif (isset($params['username'])) // use Username
{
$username = trim($params['username']);
$uid = $feu->GetUserID($username);
}
else // use $_GET['arg'][1]
{
$username = str_replace($conf['page_extension'],'', $_GET['arg'][1]);
$uid = $feu->GetUserID($username);
}
if (empty($username)) // the triage failed to produce a username or userid
{
$errorid = 3;
$error = 'could not find a username or user id to compute!';
jm_errors($errorid, $error);
return;
}
// now let's check for expired user
if ($feu->IsAccountExpired( $uid ) && (!$params['show_expired']))
{
$errorid = 4;
$error = 'This user account has expired!';
jm_errors($errorid, $error);
return;
}
if (isset($params['feu_group']))
{
if (!$feu->GroupExistsByName($params['feu_group']))
{
$errorid = 5;
$error = 'Group does not exist';
jm_errors($errorid, $error);
return;
}
// group exists
$gid = $feu->GetGroupID($params['feu_group']);
if (!$feu->MemberOfGroup($uid,$gid))
{
$errorid = 6;
$error = 'User does not belong to this group!';
jm_errors($errorid, $error);
return;
}
}
// cleared from group triage -> carry on!
if (isset($params['if_property']))
{
if (!isset($params['if_value']))
{
$errorid = 7;
$error = 'When using if_property if_value must be used!';
jm_errors($errorid, $error);
return;
}
}
$feuproperties = $feu->GetUserProperties($uid);
foreach($properties as $property)
{
foreach($feuproperties as $key=>$value)
{
if ($value["title"] == trim($property))
{
if (($value["title"] == trim($params['if_property'])))
{
if (!($value['data'] == trim($params['if_value'])))
{
// hopefully hidden user properties can be used here????
unset($result);
$errorid = 8;
$error = 'if_property does not match if_value!';
jm_errors($errorid, $error);
return;
}
}
$result[$value["title"]] = $value['data'];
}
}
} // foreach($properties as $property) <- end
if (isset($params['assign_result']))
{
$smarty->assign(trim($params['assign_result']),$result);
return;
}
return implode('<br /\>', $result);
}
So I'm about to take it for a few more tests and release it on the forge.
OK, so now is were I could use some help, if you gurus kindly would take a look and see if there are any obvious traps.
Also opinions about it's usefulness for others and suggestions?
Is there a better way of getting parameters than from $_GET array?
Thanks in advance!
BTW I noticed that the code here appears to be longer than it really is... so..... sorry for the Loooooong post.