SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 194 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

The
most commonly used content event is onPrepareContent. This event, always the
first of all the content events to be triggered, is used to modify the text content.
Let's imagine we want to create a content plugin which will replace all occurrences
of ':)' with a small smiley face icon. This is how we could implement this:
// no direct access
defined('_JEXEC') or die('Restricted access');
// register the handler
$mainframe->registerEvent('onPrepareContent',
'plgContentSmiley');
/**
* Replaces :) with a smiley icon.
*
* @param object Content item
* @param JParameter Content parameters
* @param int Page number
*/
function plgContentSmiley(&$row, &$params, $page)
{
$pattern = '/\:\)/';
$icon = '';
$row->text = preg_replace($pattern, $icon, $row->text);
}
Notice that we do not return the changes, we modify the referenced $row object.
The $row object is the content item; it includes a great many attributes. This table
describes the attributes that we are most likely to modify:
Attribute Description
created Created date and time in the format 0000-00-00 00:00:00.


Pages:
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206