Login


Warning: include(/home2/sonicfog/public_html/joobi/entry.php) [function.include]: failed to open stream: No such file or directory in /home2/sonicfog/public_html/plugins/content/subscription_content_plugin.php on line 18

Warning: include(/home2/sonicfog/public_html/joobi/entry.php) [function.include]: failed to open stream: No such file or directory in /home2/sonicfog/public_html/plugins/content/subscription_content_plugin.php on line 18

Warning: include() [function.include]: Failed opening '/home2/sonicfog/public_html/joobi/entry.php' for inclusion (include_path='.:/opt/php52/lib/php') in /home2/sonicfog/public_html/plugins/content/subscription_content_plugin.php on line 18
We were unable to load Joobi library for the plugins Subscription Restriction on Articles. If you removed the joobi folder, please also remove this plugins from the Joomla plugins manager.
This article is targeted toward Joomla developers.

The developers of Joomla! tout the new version (1.5) as a dream for extension developers because of of JFactory and how easy it is to access everything you need. That is probably true, but if you are a developer that is familiar with Joomla 1.0 you may be challenged, at least at first, to find the things you need.

This article tackles on aspect of finding the things you need as a Joomla! 1.5 extension developer, the JUser object.

Each time index.php is called the JFactory class of methods is invoked. This make a lot of extension classes available. One of these is JUser. You can call this class by using the following code.

<?php $user =& JFactory::getUser(); ?>

Now you can use the $user object to access the information contained in the Joomla jos_user table.
  • id
  • name
  • username
  • email
  • password
  • password_clear used when the password is being reset
  • usertype registered, publisher, author, etc
  • gid
  • block
  • registerDate
  • lastvisitDate
  • guest set to 1 when the user is not logged in
Here is an example
$user_email = $user->email;
echo $user_email;

or

if ($user->guest) {
    
echo "You must be logged in to view this info.";

} else {

In addition, we can get the preference parameters using the getParam() method of the $user object.

$user =& JFactory::getUser();
$language = $user->getParam('language', 'default');

Another neat trick is to borrow from a core component it's access rights. For example, let's say you are building a component that has similar access rights to the Content component (com_content). (These rights are stored at libraries/joomla/user/authorization.php) You can borrow these access rights from that component and use them in your component.  Here is an example:

$user =& JFactory::getUser();

if ($user->authorize('com_content', 'edit', 'content', 'all')) {
echo "You have editor rights in my new component.";
// I gave you these rights because you had editor rights in the Content component.
} else {
echo "You are not an editor in my custom component.";
}

if ($user->authorize('com_content', 'publish', 'content', 'own')) {
echo "Your a moderator in my custom component.";
// I gave you these rights because you had publisher rights in the Content component.
} else {
echo "You are not a moderator in my custom component.";
}


Another method for granting or denying access is through the ACL system. It's a separate class than $user but its similar and related so lets cover it here. I can add an access attribute the to the ACL system. First call the acl object then add the attributes like this.

$auth =& JFactory::getACL();
  
  $auth->addACL('com_userinfo15', 'key_holder', 'users', 'super administrator');
  $auth->addACL('com_userinfo15', 'key_holder', 'users', 'administrator');
  $auth->addACL('com_userinfo15', 'key_holder', 'users', 'manager');
 
  $user =& JFactory::getUser();
  
  if ($user->authorize('com_userinfo15', 'key_holder')) {
    echo "You have the keys to the kingdom.";
  } else {
    echo "You are locked out without a key.";
  }
I've added my made up, "key_holder" status for super administrators, administrators and managers. That group that I've created with this code has the keys to the kingdom in my custom component.

Well, that's it for JUser for now. Happy coding!