Publisher - Elo
Welcome, Guest
Main » Articles

Total entries in catalog: 1
Shown entries: 1-1
Pages:

This is a tutorial for creating very simple content-plugin "Hello World" for Joomla 1.5 native.

1. Create a folder plg_helloworld on your local computer.

2. Create two text files encoded in UTF-8 in it, and name it helloworld.xml and helloworld.php

3. Example of code for file helloworld.xml is here:

<!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/plugin-install.dtd">
<install version="1.5" type="plugin" group="content">
<name>Content - Hello World</name>
<author>EloPaint</author>
<authorEmail>elop14@gmail.com</authorEmail>
<authorUrl>http://elopaint.ucoz.com</authorUrl>
<creationDate>2011</creationDate>
<version>1.0</version>
<description>This is Joomla 1.5 content plugin, that replace {helloworld} for "Hello world!" text everywhere in the website content.</description>
<files>
<filename plugin="helloworld">helloworld.php</filename>
</files>
<params/>
</install>

4. Example of code for helloworld.php file:

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
// import library dependencies
jimport('joomla.event.plugin');
class plgContentHelloworld extends JPlugin
{
    //constructor
    function plgContentHelloworld( &$subject )
    {
        parent::__construct( $subject );
    }
   
    function onPrepareContent( &$row, &$params, $limitstart=0 )
    {   
        //plugin codes here
        if (preg_match("#{helloworld}#s", $row->text)) {
           
            $helloworldCode = 'Hello world!';
            $row->text = preg_replace("#{helloworld}#s", $helloworldCode, $row->text);
        }
        //no return value
    }
}
?>

5. Zip folder plg_helloworld, load and instal it on Joomla 1.5 as usual. Enable plugin "Content - Hello World" in Joomla.

6.Write {helloworld} somewhere in article and you look text "Hello world!" in this place. That's all :)

You can download source code by this link: plg_helloworld.zip

 

Joomla | Views: 2271 | Added by: EloPaint | Date: 2011-09-27 | Comments (0)