0

Hello I have two token functions that I use in my bridge from Second Life(LSL Script) to joomla it creates a the Token for the info coming from and to SL on the site.

Is there a way i can make these function global.So that i can call it from any of the pages in my Component rather then put them in every page.

//This is the Token decode function
function security_array_decode($myuuid, $token_salt)
{
 $s_array = array(); 
 $i = 0;
  do {
     $untime = time() - $i;
     $arr = array($myuuid, $untime, $token_salt);
     $token_key = sha1(join("",$arr));
     $s_array[] = $token_key;
     $s_array[] = $untime;
     ++$i;
   } while ($i <= 5);
  return $s_array;
 }


//This is the Token encode function
function security_array_encode($myuuid, $token_salt)
{
     $untime = time();
     $arr2 = array($myuuid, $untime, $token_salt);
     $token_key = sha1(join("",$arr2));
  return $token_key;
}

2 Answers 2

1

I would suggest you create a file in the helper folder of your component with a class containing your code shown above in a couple of methods and then each time your component needs to use the code you can do so with a simple call to the desired method.

Helper files tend to be for code that doesn't really fit into Model, View or Controller folders and potentially could be called from more than one place so your requirement I think fits the bill.

You may need to load the helper file(s) first before you can call it.

For example most of the core components have helper files and reading through them you can see how they are used and called. A quick search in JSE shows up several questions and answers on loading and calling Helpers and google has plenty to read also.

A look in

/administrator/components/com_weblinks/helpers/weblinks.php

shows a number of methods to create sub menus & count items. And then in

/administrator/components/com_weblinks/view/weblinks/view.html.php

on line 43 you can see this code that calls the addSubmenu method in the helper file.

    WeblinksHelper::addSubmenu('weblinks');
1

You could put both functions in a class in the helper.php file of your component.

Include the helper file in the entry point of your component ( in /components/com_yourcomponentname/yourcomponentname.php)

and then you could use the methods in all parts of your component.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.