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

JDocument


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

This is the Joomla! base document object that encapsulates and caches a response during the execution of an application. This enables us to make modifications to any part of the document irrespective of where we are in the output process. For more information about JDocument refer to Chapter 2, Getting Started and Chapter 9, Customizing the Page.

Direct descendents

JDocumentRAW

Provides an interface to parse and display raw output

JDocumentError

Provides an interface to parse and display an error page

JDocumentHTML

Provides an interface to parse and display a HTML page

JDocumentPDF

Provides an interface to parse and display a PDF page

JDocumentFeed

Provides an interface to parse and display a feed page

Properties

mixed $_buffer = null

Buffered rendered output

string $_charset = 'utf-8'

Character encoding string, default is utf-8

object $_engine = null

Rendering engine, used by subclass JDocumentPDF

string $_generator

Document metadata generator

string $_lineEnd = ''\12''

The line end character or string

string $_mdate = ''

The document's modified date

array $_metaTags

An array of meta tags

string $_mime = ''

Document mime type

string $_namespace = ''

Document namespace, not used by document subclasses

string $_profile = ''

Document profile, not used by document subclasses

array $_script

Array of scripts placed in the document header

array $_scripts

Array of linked scripts

array $_style

Array of style declarations placed in the document header

array $_styles

Array of linked stylesheets

string $_tab = ''\11''

Tab character or string

string $_type = null

Document type

string $base = ''

Document base URL

string $description = ''

Document description

string $direction = 'ltr'

Text direction (ltr or rtl); default is left-to-right

string $language = 'en-gb'

Language setting, default is Great Britain English

string $link = ''

Document full URL

string $title = ''

Document title

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 JDocument object. Derived subclasses call parent::__construct($options). The $options associative array can contain the keys lineend, charset, language, direction, tab, link, and base.

Redefines JObject::__construct(); overridden in descendant classes.

JDocument __construct($options)

  • array $options: Associative array of options

addScript

This method adds a linked script to the document.

void addScript($url, [$type = 'text/javascript'])

  • string $url: The URL to the linked script

  • string $type: The MIME type of script; defaults to 'text/javascript'

  • void: No return type

addScriptDeclaration

This method embeds a script in the document.

void addScriptDeclaration($content, [$type = 'text/javascript'])

  • string $content: The script content.

  • string $type: The MIME type of the script; defaults to 'text/javascript'

  • void: No return type

addStyleDeclaration

This method embeds a style declaration in the document.

void addStyleDeclaration($content, [$type = 'text/css'])

  • string $content: The style content.

  • string $type: The MIME type of the style; defaults to 'text/css'

  • void: No return type

addStyleSheet

This method adds a linked stylesheet to the document.

void addStyleSheet($url, [$type = 'text/css'] , [$media = null], [$attribs = array()])

  • string $url: The URL to the linked style sheet

  • string $type: The MIME type of style; defaults to 'text/css'

  • string $media: The media type of this stylesheet

  • array $attribs: array of style attributes

  • void: No return type

getBase

This method returns the base URI of the document.

string getBase()

  • string: Returns base URI

getBuffer

This method returns the content of the document buffer. Redefined in descendants:

  • JDocumentHTML::getBuffer()

string getBuffer()

  • string: Returns contents of the document buffer

getCharset

This method returns the document character set encoding.

string getCharset()

  • string: Returns the character set encoding

getDescription

This method returns the document description.

string getDescription()

  • string: Returns the document description

getDirection

This method returns the text direction of the document, ltr (left-to-right) or rtl (right‑to‑left).

string getDirection()

  • string: Returns the text direction

getGenerator

This method returns the document generator string; the default is 'Joomla! 1.5 - Open Source Content Management'.

string getGenerator()

  • strin g: Returns the document generator string

getHeadData

This method returns an associative array containing the document header data. The header data array includes the title, description, link, metatags, links, stylesheets, style, scripts, script, and custom keys and values.Redefined in descendants:

  • JDocumentHTML::getHeadData()

array getHeadData()

  • array: Returns an associative array of header data

static getInstance

This method returns a reference to a global instance of a JDocument subclass object, based on $type(error, feed, HTML, PDF, or RAW) and $attributes. Use JFactory::getDocument() to get the application document.

JDocument &getInstance([$type = 'html'], [$attributes = array()])

  • string $type: The document type to instantiate

  • array $attributes: Associative array of options

  • object: Returns a reference to a JDocument object

getLanguage

This method returns the document language.

string getLanguage()

  • strin g: Returns the document language; the default is 'en-GB'

getLink

This method returns the document base URI.

string getLink()

  • string: Returns the document base URI

getMetaData

This method returns the document metadata. If the metadata is http-equiv (equivalent to an HTTP header) then specify $http_equiv as true.

string getMetaData($name, [$http_equiv = false])

  • string $name: The value of name or http-equiv tag

  • boolean $http_equiv: The META type http-equiv; defaults to null

  • string: Returns the document metadata

getModifiedDate

This method returns the document modified date.

string getModifiedDate()

  • string: Returns the document modified date

getTitle

This method returns the document title.

string getTitle()

  • string: Returns the document title

getType

This method returns the document type.

string getType()

  • string: Returns the document type

loadRenderer

This method returns a reference to an instance of a JDocumentRenderer subclass object. The $type can be Atom, RSS, Component, Head, Message, Module, or Modules. If you define your own JDocumentRenderer class you must include the class before using this method.

JDocumentRenderer &loadRenderer($type)

  • string $type: The document renderer type

  • object: Returns a reference to a JDocumentRenderer object

render

This method outputs the rendered document. This method varies depending upon the subclass. Redefined in descendants:

  • JDocumentRAW::render()

  • JDocumentError::render()

  • JDocumentHTML::render()

  • JDocumentPDF::render()

  • JDocumentFeed::render()

string render([$cache = false], [$params = array()])

  • boolean $cache: If true, cache the output

  • array $params: An associative array of attributes

  • string: Returns the rendered document

setBase

This method sets the base URI of the document.

void setBase($base)

  • string $base: The document base URI

  • void: No return type

setBuffer

This method sets the buffered contents of the document. Redefined in descendants:

  • JDocumentHTML::setBuffer()

void setBase($content)

  • string $content: The content to be set in the buffer

  • void: No return type

setCharset

This method sets the character set encoding for the document. This does not convert content to the new character set.

void setCharset([$type = 'utf-8'])

  • string $type: The character set encoding string

  • void: No return type

setDescription

This method sets the document description.

void setDescription($description)

  • string $description: The description of the document

  • void: No return type

setDirection

This method sets the text direction of the document, ltr (left‑to‑right) or rtl (right‑to‑left).

void setDirection([$dir = 'ltr'])

  • string $dir: The text direction

  • voi d: No return type

setGenerator

This method sets the document generator; the default is 'Joomla! 1.5 – Open Source Content Management'.

void setGenerator($generator)

  • string $generator: The generator name

  • void: No return type

setHeadData

This method sets the head data of the document. The head $data array is an associative array that must include the title, description, link, metatags, links, stylesheets, style, scripts, script, and custom keys and values. Redefined in descendants:

  • JDocumentHTML::setHeadData()

void setBase(array $data)

  • array $data: The document head data in array form

  • void: No return type

setLanguage

This method sets the global document language declaration; the default is Great Britain English (en-GB).

void setLanguage([$lang = 'en-gb'])

  • string $lang: The global document language

  • void: No return type

setLineEnd

This method sets the document EOL character string. The $style can be win, unix, mac, or a custom EOL character string.

void setLineEnd($style)

  • string $style: The document EOL character string

  • void: No return type

setLink

This method sets the document's full URL.

void setLink($url)

  • string $url: The document URL.

  • void: No return type

setMetaData

This method sets or alters a document meta tag. If the metadata is http-equiv (equivalent to an HTTP header) then specify $http_equiv as true. If $name is 'generator' or 'description' this method will call setGenerator() or setDescription() respectively; for all others the $_metatags array is updated.

void setMetaData($name, $content, [$http_equiv = false])

  • string $name: The value of name or http-equiv tag

  • string $content: The meta tag content

  • boolean $http_equiv: The META type http-equiv; defaults to null

  • void: No return type

setMimeEncoding

This method sets the MIME encoding that is sent to the browser. This usually will be text/html because most browsers cannot yet accept the proper mime settings for XHTML: application/xthml+xml and to a lesser extent application/xml. See the W3C note (http://www.w3.org/TR/xhtml-media-types/) for more details.

void setMimeEncoding([$type = 'text/html'])

  • string $type: The MIME encoding string

  • void: No return type

setModifiedDate

This method sets the document's modified date.

void setModifiedDate($date)

  • string $date: The modified date

  • void: No return type

setTab

This method sets the string used to indent HTML.

void setTab($string)

  • string $string: The string used to indent ("\11","\t",' ', and so on)

  • void: No return type

setTitle

This method sets the title of the document.

void setTitle($title)

  • string $title: The document title

  • void: No return type

setType

This method sets the document type.

void setType($type)

  • string $type: The document type

  • void: No return type

_getLineEnd

This private method returns the document EOL character/string.

string getLineEnd()

  • string: Returns the document EOL character string

_getTab

This private method returns the document indentation character string.

string getTab()

  • strin g: Returns the document indentation character string