Page 1 of 1

[Solved] Coping with loss of $gCms

Posted: Mon Jan 03, 2011 5:47 pm
by arr28
EDIT: Solution is that there's no issue here in the first place! The smarty variable {$gCms} has been retired in 1.9, but the PHP variable $gCms (available in modules and UDTs) has not.
--

I'm currently using CMSMS 1.8.2 and am planning my upgrade to 1.9.2. I notice from the release notes that $gCms will no longer be accessible. My site currently relies on $gCms in 4 ways, all from within (pretty complex) UDTs. For each, what is the correct replacement code to achieve the same end?

1) Getting a page URL from the page alias

I used to use...

Code: Select all

global $gCms;
$manager = &$gCms->GetHierarchyManager();
$page_url = $manager->sureGetNodeByAlias('page-alias')->GetContent()->GetUrl();
Without using $gCms, how can I get a page URL from its alias?


2) Testing whether the logged on user is a member of a particular group

I used to use...

Code: Select all

global $gCms;
$modFEU = $gCms->modules['FrontEndUsers']['object'];
$is_in_group1 = $modFEU->MemberOfGroup($modFEU->LoggedInId(),$modFEU->GetGroupID('group1'));
Without using $gCms, how can I determine (in a UDT) if the currently logged on user is a member of a particular group?


3) Retrieving smarty variables

I used to use...

Code: Select all

global $gCms;
$smarty = &$gCms->GetSmarty();
$our_ref = $smarty->get_template_vars('ccuser')->property('our_ref');
Without using $gCms, how can I get a smarty template variable? Or, if easier, how can I retrieve a particular custom field from the currently logged on user's FEU account details? (At the moment, I'm relying on the fact the all the custom properties from the user's account are copied into a smarty template variable.)


4) Screening FEU passwords against a default

Code: Select all

global $gCms;
$modFEU = $gCms->modules['FrontEndUsers']['object'];
$is_using_default_password = $modFEU->CheckPassword($modFEU->LoggedInName(), 'default_password');
Finally, without using $gCms, how can I check a user's password against a default? (We use this to force the user to change their password away from the default that we give to new accounts.)


Answers to any or all of the above would be much appreciated. (And if your solution works in 1.8.2, please mention it because it means I can change the offending code before doing the migration rather than trying to do it all at once.)

Many thanks,

Andrew

Re: Coping with loss of $gCms (upgrading from 1.8.2 to 1.9.2

Posted: Mon Jan 03, 2011 6:14 pm
by Sonya
arr28 wrote: 1) Getting a page URL from the page alias

Code: Select all

global $gCms;
$manager = &$gCms->GetHierarchyManager();
$page_url = $manager->sureGetNodeByAlias('page-alias')->GetContent()->GetUrl();
Quick test of this UDT on 1.9.2 "Tevairoa" and it works. Where have you got the information that $gCms is "lost"? I cannot imagine it's true as a lot of modules rely on this variable.

Re: Coping with loss of $gCms (upgrading from 1.8.2 to 1.9.2

Posted: Mon Jan 03, 2011 6:18 pm
by Wishbone
According to the 1.9 announcement, the {$gCms} smarty variable has been removed. It's still available to modules. I would think it would still be available to UDTs.

Re: Coping with loss of $gCms (upgrading from 1.8.2 to 1.9.2

Posted: Mon Jan 03, 2011 6:31 pm
by Sonya
Wishbone wrote:According to the 1.9 announcement, the {$gCms} smarty variable has been removed. It's still available to modules. I would think it would still be available to UDTs.
Oh, I see. It is only about Smarty variable, it does not have any impact on PHP variable. Same name, but something completely different :)

Re: Coping with loss of $gCms (upgrading from 1.8.2 to 1.9.2

Posted: Mon Jan 03, 2011 6:41 pm
by arr28
Oh, I see. It is only about Smarty variable, it does not have any impact on PHP variable. Same name, but something completely different.
Many thanks for your help. I hadn't noticed the subtlety. Will press on with the upgrade and see how things go.