Very simple plugin for Joomla to get you started.

I see a need of basic functional Joomla plugin example. New developers can use this to get them started.

I made simple plugin for this that looks for tag in article and replaces it. Param’s, field and fieldset are also used.

Download install package for joomla 1.7 and 1.6 here http://marguspala.com/downloads/simpleplugin.zip.

simpleplugin.php

<?php
// No direct access.
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

class plgContentSimpleplugin extends JPlugin
{

        public function __construct(& $subject, $config)
        {
                parent::__construct($subject, $config);
                $this->loadLanguage();
        }

        public function onContentPrepare($context, &$article, &$params, $page=0)
        {
                $orig='/' . $this->params->get('original') . '/';
                $repl=$this->params->get('replaced');

                $article->text = preg_replace($orig, $repl, $article->text);

                return true;
        }
}

simpleplugin.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7" type="plugin" group="content">
        <name>Content - Simple plugin</name>
        <author>Margus Pala</author>
        <authorUrl>http://marguspala.com</authorUrl>
        <version>1.7.0</version>
        <description>Simple plugin that modifies article and helps you to get started. See http://marguspala.com/very-simple-plugin-for-joomla-to-get-you-started</description>
        <files>
                <filename plugin="simpleplugin">simpleplugin.php</filename>
        </files>
        <config>
                <fields name="params">
                        <fieldset name="basic">
                                <field name="original" type="text" default="replaceme" label="Original regex" description="Regex of what to replace" ></field>
                                <field name="replaced" type="text" default="youarereplaced" label="Replaced value" description="What must be written instead of original" ></field>
                        </fieldset>
                </fields>
        </config>
</extension>

 


Leave a Reply

Your email address will not be published.


*