Creating a Joomla system plugin
System plugins are loading in every pages, so it's good to make them, because you can add extra codes to ours without having to put it into our folders, which will be overwritten with the next update.
What you need is to create a folder in here:
plugins/system/
Let's call it example:
plugins/system/example
Then put three files inside it. The first one should be the index.html, which should only have this code:
<html><body></body></html>
The second file should be a php file, which should have the same name what your folder had, in my case example.php
This will be the file, which is called in everywhere, so it should have the php code, what you would like to run.
The third file is an xml file, which contains the informations of your plugin. This should have the same name too: example.xml
and the code should be something like this:
<?xml version="1.0" encoding="utf-8"?> <extension version="3.4" type="plugin" group="editors-xtd" method="upgrade"> <name>Example plugin</name> <author>John Doe</author> <creationDate>April 2015</creationDate> <copyright>Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <description>Example plugin</description> <files> <filename plugin="example">example.php</filename> <filename>index.html</filename> </files> </extension>
So the important parts are to have the files listed. After this you can install your plugin at your admin area -> Extensions -> Manage -> Discover. Then publish it at the Extensions -> Plugins. In the next example you can see the process with images.
Example - Creating a generator
Create these folders:
plugins\system\smartslidergenerator\
plugins\system\smartslidergenerator\sources\
These files with the given code:
index.html
<html><body></body></html>
smartslidergenerator.php
<?php require_once(dirname(__FILE__) . '/../../../libraries/nextend2/nextend/joomla/library.php'); require_once(dirname(__FILE__) . '/../../../libraries/nextend2/smartslider/smartslider/libraries/slider/generator/generatorFactory.php'); require_once(dirname(__FILE__) . '/../../../libraries/nextend2/smartslider/smartslider/libraries/plugins/N2SliderGeneratorPluginAbstract.php'); class N2SSPluginGeneratorCustom extends N2SliderGeneratorPluginAbstract { protected $name = 'custom'; protected $url = '#'; public function getLabel() { return 'Custom'; } public function isInstalled() { return true; } protected function loadSources() { new N2GeneratorCustom($this, 'source', n2_('Source')); } public function getPath() { return dirname(__FILE__) . DIRECTORY_SEPARATOR; } } N2SSGeneratorFactory::addGenerator(new N2SSPluginGeneratorCustom);
smartslidergenerator.xml
<?xml version="1.0" encoding="utf-8"?> <extension version="3.4" type="plugin" group="editors-xtd" method="upgrade"> <name>Smart Slider Custom Generator</name> <author>Gabor Racz</author> <creationDate>April 2015</creationDate> <copyright>Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <description>Smart Slider custom generator</description> <files> <filename plugin="smartslidergenerator">smartslidergenerator.php</filename> <filename>index.html</filename> </files> </extension>
dynamic.png
This should be the image you want in our backend.
Go into the sources folder you created, and put this file in it:
smartslidergeneratorsource.php
<?php N2Loader::import('libraries.slider.generator.abstract', 'smartslider'); class N2GeneratorCustom extends N2GeneratorAbstract { protected $layout = 'image_extended'; public function renderFields($form) { parent::renderFields($form); $filter = new N2Tab($form, 'filter', n2_('Filter')); new N2ElementText($filter, 'mytext', 'My text', ''); } protected function _getData($count, $startIndex) { $data = array(); $data[0]['my_variable'] = 'one'; $data[1]['my_variable'] = 'two'; $data[2]['my_variable'] = 'three'; return $data; } }
This file is the most important, so you are putting the possible options here and return the result inside the _getData function. To better understand this part, check out the generator developer documentation.
Now go to the Extensions -> Manage
click on Discover -> Discover
Select the Smart Slider Custom Generator and install it
Then go to the Extensions -> Plugin Manager
Filter out the system plugins
And put this plugin after our Nextend Smart Slider 3 and Nextend2 Library plugins by clicking on the ordering
And drag 'n drop it lower
Then you can enable this plugin
And if you will go to our backend to create a new dynamic slide
You should be able to see the new generator
And the records
You could put the contents of the smartslidergenerator folder into a zip file too: smartslidergenerator.zip
and then you would be able to install this generator into more websites too, through your Extensions manager.