Jump to content

[RESOLVED] Impossbile to use $smarty in custom hooks on 5.2.1


Recommended Posts

On 5.1.3, I had a few custom hooks that utilizes pulling smarty variables via:

function foo_bar($vars) {
global $smarty;
$module = $smarty->get_template_vars('modulename');
}

 

These functions stopped working on 5.2.1, by adding var_dump($smarty); to the code, it returns NULL while it should return proper results. What was changed to cause this? Any alternative? Or is there a fix? This is a rather huge issue; at least to us.

Link to comment
Share on other sites

This used to work before. However, here's the response I got for my ticket:

 

Hello

 

The $smarty object has been removed from global as part of some wider ongoing refactoring of the WHMCS core. The proper solution for defining custom variables is and has always been to simply return an array of the variables you want to set from your ClientAreaPage hook simply like this:

 

return array( 'var1' => 'xyz', 'var2' => 'abc', etc... );

 

Hope this helps.

 

I am very unhappy with this :-/

Link to comment
Share on other sites

... except when the ClientAreaPage isn't called. "..as part of some wider ongoing..."... sounds like they don't even know why they are doing it. lol

 

I agree they need to refactor the core (along with their update / upgrade processes but I digress) but hiding smarty away isn't very wise imho - it's been exposed and available for at least 5 years and was reliably in place from version to version, even major updates.

 

They also seem to make drastic changes for some unknown reason. For example, they used tinymce in version 5.0, then nicEditor which was very lightweight and usable and friendly in 5.1, now they are back to tinymce in 5.2. This would seem to be a somewhat fundamental item that shouldn't get changed frequently, at least in minor releases as 5.1, 5.2 etc.

 

As a 3pd, I dread the coming 6 week update process... can you imagine having to refactor every product every 6 weeks? I would be looking for another platform I think if that happens :(

Link to comment
Share on other sites

I do development on WHMCS, but I'd have to be honest in saying I'm trying to catch up on the changes they made for my products and wouldn't be able to get to anything right away.

 

Did you look at the forum post I had linked to ? It provides a method of pulling the template variables from the smarty object hidden in the global ca variable, but does require PHP 5.3 unfortunately. Hopefully WHMCS will roll out with some methods on their object to be able to retrieve the object variables.

Link to comment
Share on other sites

Yes, I saw it. But I was unable to incorporate it with my code. This is what I could use help with. I have 2 codes, small and large, if I figure out how to do it with the small, will figure out the large. Here's my small code below:

 

<?php
function unblockme_show($vars) {
global $smarty;

$module = $smarty->get_template_vars('modulename');
$server = $smarty->get_template_vars('server');
$status = $smarty->get_template_vars('status');
$lang_arr = $smarty->get_template_vars('LANG');
$activetxt = $lang_arr['clientareaactive'];
if (($module == "cpanel") && ($server) && ($status == $activetxt)) {
	$isactive = 1;
} else {
	$isactive = 0;
}
$smarty->assign("unblockme_isactive", $isactive);
}

add_hook("ClientAreaPage", 1, "unblockme_show");

?>

Link to comment
Share on other sites

Are you sure the clienteareaactive string hasn't changed and that the other variables are still in place? I recall their changelog saying they have a new method for testing the status perhaps they also wiped that variable from being accessible?

 

Also, it looks like you are comparing the status set in the module with a language string, which I wouldn't think would be reliable (though I cannot say for sure what the status variable would hold).

 

The function I wrote and linked you to would pull the variable if you made a call like 'getvar( 'modulename' )' it should come back with the modulename if it is set in smarty or in the ca variable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated