Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Overview of this book

Joomla! is one of the world’s top open source content management systems, which enables you to build websites and powerful online applications. Out of the box, Joomla! does a great job of managing the content needed to enhance the functionality of your website. But for many people, the true power of Joomla! lies in its application framework that makes it possible for thousands of developers around the world to create powerful add-ons and extensions. This book will guide you through the complexities of implementing add-ons, components, modules, and plugins in Joomla! 1.5. If you feel that you’ve mastered the basics of creating Joomla! extensions, then this book will take you to the next level. Packed with expert advice on all aspects of programming with Joomla!, this book is an invaluable reference guide you will turn to again and again for your Joomla! development tasks. The book starts by explaining the structure and design of the Joomla! Framework. Then we move on to extending and storing data in standard fields and dealing with multilingual requirements. Further, you will discover best practices, design, and coding methods for Joomla! components, modules, plugins, and other extensions. Along the way, you will actually design and create a component, module, and plugin that work together to add functionality to the Joomla! framework. You will also learn about customizing the page output using JavaScript effects, making use of Web Services from within Joomla! and ensuring that your code is secure and error-free. You will discover how to easily create sophisticated extensions that are robust, user-friendly, and professional by taking advantage of the many libraries and utilities provided by the Joomla! framework. A comprehensive, up-to-date reference to the Joomla! Framework API is also included in the book. Finally, we will discuss advanced methods for rendering your extensions more robust, secure, and professional.
Table of Contents (18 chapters)
Mastering Joomla! 1.5 Extension and Framework Development
Credits
About the Author
About the Reviewer
Preface

JUser


extends JObject , located in / joomla/user/user.php

This class handles a site user. If the user is not logged in, $id and $gid will be zero and $usergroup will be null. For further information on using the JUser class refer to Chapter 4, Extension Design.

Properties

string $activation = null

Activation string used to verify account registration.

integer $aid = null

Access group ID.

integer $block = null

Access blocked: 0=not blocked, 1=blocked.

string $email = null

Email address.

integer $gid = null

Group ID; relates to the legacy #__groups table.

boolean $guest = null

Guest user.

integer $id= null

User ID; relates to the $__users.id field.

string $lastvisitdate = null

Date on which the user last visited the site.

string $name = null

The user's actual name or nickname.

string $params = null

INI parameter string used when updating and creating users.

string $password = null

MD5-hashed password.

string $password_clear = ''

Clear password; only available when a new password is set for a user.

string $registerdate = null

Date on which the account was registered.

integer $sendEmail = null

Receive system emails: 0=no, 1=yes.

string $username = null

The user's login name.

string $usertype = null

The user group that the user is a member (ARO group). If the user is not logged in this will be null.

string $_errorMsg = null

Log of errors separated by new lines.

JParameter $_params = null

Parameters from #__users.params field. Metadata available from administrator/components/com_users/user.xml.

Inherited properties

Inherited from JObject:

  • JObject::$_errors

Inherited methods

Inherited from JObject:

  • JObject::JObject()

  • JObject::__construct()

  • JObject::get()

  • JObject::getError()

  • JObject::getErrors()

  • JObject::getProperties()

  • JObject::getPublicProperties()

  • JObject::set()

  • JObject::setError()

  • JObject::setProperties()

  • JObject::toString()

Methods

Constructor __construct

Class constructor. Builds a new JUser object and loads the user's details from the database. A new JParameter object is created and if the user $identifier exists the user's details will be loaded. If no $identifier is specified (a new user) the user's details will be initialized. Redefinition of JObject::__construct(); class constructor.

JUser __construct([$identifier = 0])

  • integer $identifier: The user id

authorize

This method determines if the user is authorized to perform an action. It checks the JUser object authorization against an access control object and optionally an access extension object. It acts as a pass-through for JAuthorization. This is only for GACL authorization.

boolean authorize($acoSection, $aco, [$axoSection = null], [$axo = null])

  • string $acoSection: The ACO section value

  • string $aco: The ACO value

  • string $axoSection: The AXO section value; optional

  • string $axo: The AXO value; optional

  • boolean: Returns true if authorized

bind

This method binds an associative array to the JUser object. There are two ways to use this: updating an existing user and creating a new user. Create is assumed if the object property $id is empty (zero is considered empty).

When updating an existing user, $array can contain any of the public properties associated with a JUser object. If user parameters are going to be bound they must be passed in a key named params and be in INI string format. The values are then bound to the object.

When creating a new user the $username property must already be set. If password is omitted from $array a random password will be generated.

boolean bind(&$array)

  • array $array: The associative array to bind to the object

  • boolean: Returns true upon success

defParam

This method defines a parameter and sets its value if it does not exist.

mixed defParam($key, $value)

  • string $key: The parameter key name

  • mixed $value: The parameter value

  • mixed: Returns the parameter value

delete

This method deletes the JUser object from the database.

boolean delete()

  • boolean: Returns true upon successful deletion

getInstance

This method returns a reference to a global instance of a JUser object. If the object does not exist, it will be created. $id can be a string or an integer. If it is a string it will be assumed that it is a username, and if it is an integer it will be assumed that it is a user's ID. To get a reference to the current user object, use JFactory::getUser(). This method must be invoked as follows:

$user =& JUser::getInstance($id);

JUser &getInstance($id = 0)

  • mixed $id: The user to load; can be an integer or string

  • object: Returns a reference to a global JUser object

getParam

This method returns a user parameter from the $_params property. If the parameter does not exist the value of $default will be returned.

mixed getParam($key, [$default = null])

  • string $key: The parameter key name

  • mixed $default: The default value

  • mixed: Returns the parameter value

getParameters

This method returns a reference to the user's JParameters object. It attempts to load an XML setup file based on the user's $usertype. The filename of the XML file is the same as the $usertype. The method uses a static variable to store the parameter setup file base path. You can call this function statically to set the base path if needed.

JParameter &getParameters([$loadsetupfile = false], [$path = null])

  • boolean $loadsetupfile: If true loads the parameter XML setup file

  • string $path: The parameter XML setup file base path

  • object: Returns a reference to the user's JParameter object

getTable

This method returns a reference to a new JTableUser object loaded with the current user's details. This method uses a static variable to store the table name of the user table it instantiates. The method can be called statically to set the table name if needed.

JTableUser &getTable([$type = null], [$prefix = 'JTable'])

  • string $type: The custom user table name to be used; default is 'User'

  • string $prefix: The parameters XML setup file base path

  • object: Returns a reference to the user's JTableUser object

load

This method loads a user based on the $id and sets the user properties.

boolean load($id)

  • integer $id: The id of the user to load

  • boolean: Returns true upon success

save

This method saves the JUser object to the database. If $updateOnly is true, then the creation of a new user will not be permitted. If this is the case, and an attempt is made to save a new user, the method will still return true. Before saving the user a number of sanity checks are made, including data validation and authorization verification. If any of these fail then the method will return false.

boolean save([$updateOnly = false])

  • boolean $updateOnly: If true creation of a new user will not be permitted

  • boolean: Returns true upon success

setLastVisit

This method is a pass-through method to the table for setting the last visit date. The method updates the user's database record last visit date but does not update the lastVisitDate property of the object.

boolean save([$timestamp = null])

  • integer $timestamp: The timestamp; defaults to 'now'

  • boolean: Returns true upon success

setParam

This method sets the value of a user parameter.

mixed setParam($key, $value)

  • string $key: The parameter key

  • mixed $value: The parameters value

  • mixed: Returns the set parameter value

setParameters

This method loads the user JParameter object and stores it in $_params.

void setParameters($params)

  • object $params: The user JParameter object to load

  • void: No return type