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

Appendix A. Joomla! Core Classes

This appendix details the Joomla! core classes. Additional documentation can be found at the official API site: http://api.joomla.org although the Joomla! code should be your final source for the most accurate and current information. This appendix covers:

  • JApplication

  • JController

  • JDatabase

  • JDocument

  • JDocumentRenderer

  • JFactory

  • JModel

  • JObject

  • JPlugin

  • JTable

  • JUser

  • JView

JApplication

abstract, extends JObject , located in / joomla/application/application.php

This is a base application class that acts as a factory class for application specific objects and provides many supporting API functions. Derived classes should supply the route(), dispatch() and render() functions. The frontend JSite and backend JAdministrator classes as well as the installation JInstallation class extend the JApplication class. This class encapsulates the process from request to response. For more information about the JApplication class refer to Chapter 2 , Getting Started.

Properties

string $scope

The scope of the application

integer $_clientId

The type of application

array $_messageQueue

The application message queue

array $_name

The name of the application

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()

Deprecated methods

The following methods have been deprecated as of version 1.5; their use is not recommended. Use the recommended alternative instead.

Deprecated Method

Recommended Alternative

addCustomHeadTag()

JDocument::addCustomTag()

addMetaTag()

JDocument::setMetaData()

appendMetaTag()

JDocument::setMetaData()

appendPathway()

JPathway::addItem()

getBasePath()

JURI::getBase()

getBlogCategoryCount()

JMenu::getItems()

getBlogSectionCount()

JMenu::getItems()

getContentItemLinkCount()

JMenu::getItems()

getCustomPathway()

JPathway::getPathway()

getGlobalBlogSectionCount()

JMenu::getItems()

getHead()

JDocument::getHead()

getItemid()

ContentHelper::getItemid()

getPageTitle

JDocument::getTitle()

getPath()

JApplicationHelper::getPath()

getStaticContentCount()

JMenu::getItems()

getUser()

JFactory::getUser()

prependMetaTag()

JDocument::setMetaData()

setPageTitle()

JDocument::setTitle()

Methods

Constructor __construct

Class constructor. Builds a new JApplication object for the specified client application. Subclasses generally do not require the $config parameter. The $config array will contain at least four elements:

  • clientID, identifies the application client: 0=site, 1=admin, 2=installation

  • session_name, the default session name

  • session, set to true to enable sessions

  • config_file, the configuration file name including extension

JApplication __construct([$config = array()])

  • integer $config: Configuration settings

close

This method closes the application gracefully.

void close($code)

  • integer $code: Exit code

dispatch

This abstract method pulls the option from the request object, maps it to the relevant component, and executes the component, storing the rendered result in the global JDocument object. If the component does not exist, it determines a default component to dispatch. Descendant classes should provide their own dispatch() method.

void dispatch($component)

  • string $componen t: Name of component to be dispatched

enqueueMessage

This method adds a new message to the application message queue and clears the session message queue.

void enqueueMessage($msg, [$type = 'message'])

  • string $msg: The message to enqueue

  • string $type: The message type

getCfg

This method returns a configuration value

mixed getCfg($varname)

  • string $varname: Name of the configuration value

  • mixed: Returns the configuration value

getClientId

This method returns the client id of the application currently running.

integer getClientId()

  • integer: Returns id of the running application: 0=site, 1=admin, 2=installer

getInstance

This method returns a reference to the global JApplication object. If the application object does not exist, it creates it.

JApplication &getInstance($client, [$config = array()], [string $prefix ='J'])

  • mixed $client: A client identifier or name

  • array $config: Optional associative array of configuration settings

  • string $prefix: Optional prefix string for the application name

  • string: Returns JApplication object

getMenu

This method returns a reference to the application JMenu object.

JMenu &getMenu([$name = null], [$options = array()])

  • string $name: Optional name, uses the application name if missing

  • array $options: Optional associative array of configuration settings

  • object: Returns a reference to the JMenu object

getMessageQueue

This method returns a copy of the application message queue. If no application messages exist and there are session messages, the session message queue will be moved to the application message queue.

array getMessageQueue()

  • array: Returns array of system messages in the queue

getName

This method returns the application dispatcher name. By default, it is derived from the class name, or it can be set by passing a $config['name'] in the application class constructor.

string getName()

  • string: Returns the name of the dispatcher

getPathway

This method returns a reference to the application JPathway object that maintains an array of breadcrumbs.

JPathway &getPathway([$name = null], [$options = array()])

  • string $name: Optional application name

  • string $options: Optional associative array of configuration settings

  • object: Returns a reference to the JPathwa y object

getRouter

This method returns a reference to the application JRouter object.

JRouter &getRouter([$name = null], [$options = array()])

  • string $name: Optional application name

  • string $options: Optional associative array of configuration settings

  • object: Returns a reference to the JRouter object

getTemplate

This method returns the name of the current application template. This method must always be overridden by a subclass. The base JApplication::getTemplate() method simply returns 'system'. Subclasses (JAdministrator and JSite for example) that extend JApplication override this method to return the current template.

string getTemplate()

  • string: Returns the name of the current application template

getUserState

This method returns a value from the user session registry.

mixed getUserState($key)

  • string $key: Session registry key name

  • mixed: Returns a user session registry value, null if key is not found

getUserStateFromRequest

This method updates and returns a value from the user state registry. If a $default value is provided and the $key does not exist it will be inserted into the user state registry. For valid type values see JFilterInput::clean().

string getUserState($key, $request, [$default = null], [$type = 'none'])

  • string $key: Session registry key name to retrieve the value

  • string $request: Session registry key name to retrieve the value

  • string $default: Optional default value

  • string $type: Optional filter for the variable

  • string: Returns the updated user state variable

initialise

This method initializes the application. Prepares the application language, defines date formats, and builds the application router. Subclasses JSite and JAdministrator have their own initialise() method that call parent::initialise() to complete their initialization process.

void initialise([$options = array()])

  • array $options: An optional associative array of configuration settings

  • void : No return type

isAdmin

This method determines whether the current application is the administrator backend (ClientID is 1.)

boolean isAdmin()

  • boolean: Returns true if ClientID = 1

isSite

This method determines whether the current application is the site frontend(ClientID is 0.)

boolean isSite()

  • boolean: Returns true if ClientID = 0

login

This method passes the username and encoded password to the onLoginUser event, which is responsible for user validation. The username and encoded password are sent as credentials (along with other possibilities) to each observer (authentication plugin) for user validation. A successful validation updates the current session record with the user's details.

boolean login($credentials, [$options = array()])

  • array $credentials : Array('username' => string, 'password' => string)

  • array $options: Array('remember' => boolean)

  • boolean: Returns true upon successful login

logout

If a user is logged-in, this method logs the user out. It passes the current user information to the onLogoutUser event and reverts the current session record back to anonymous parameters.

boolean logout([$userid = null], [$options = array()])

  • mixed $userid: The user to logout, can be an integer or a string

  • array $options: Array('clientid' => array of client ids)

  • boolean: Returns true upon successful logout

redirect

This method redirects the application to the specified URL and optionally enqueues a message in the system message queue (which will be displayed the next time a page is loaded) using the enqueueMessage method. This method closes the application. If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently" code in the header pointing to the new location. If the headers have already been sent this will be accomplished using a JavaScript statement.

void redirect($url, [$msg = ''], [$msgType = 'message'])

  • string $url: The redirect URL; can only be a http/https URL

  • string $msg: An optional message to display on redirect

  • string $msgType: An optional message type

  • void: No return type

registerEvent

This method registers a handler to a particular event group with the global event dispatcher.

void registerEvent($event, $handler)

  • string $event: The event name

  • mixed $handler: The handler, a function or an instance of an event object

  • void : No return type

render

This method renders the response by pushing the document buffers into the template placeholders, retrieving data from the document and pushing it into the JResponse buffer. Descendant classes should provide their own render() method.

void render()

  • void: No return type

route

This method routes the application by examining the request environment to determine which component should receive the request. The component optional parameters are then set in the request object that will be processed when the application is dispatched. This method chooses the route through the application based on the request URI. Descendant classes should provide their own route() method.

void route()

  • void: No return type

setUserState

This method sets the value of a user state variable.

mixed setUserState($key, $value)

  • string $key: The path of the state variable

  • string $value: value of the variable

  • mixed: Returns the previous state, if one existed

triggerEvent

This method will notify any registered event handlers that are associated with the event that an event has occurred. $args is exploded and each element is passed as an individual argument to the handler.

array triggerEvent($event, [$args = null])

  • string $event: The event name

  • array $args: An optional array of arguments

  • array: Returns an array of results from each function call