NOTE: DO NOT MAKE CHANGES IN THE Definition.class.php file if the plugin is active.
Post Affiliate Pro is built on GwtPhp Framework which allows plugins to be connected to the application. All plugins need to be placed in plugins/ folder and written in PHP. You can find some plugin examples bellow.If you want to create new plugin you have to follow these steps:
- create folder in plugins/ directory. e.g plugins/SysInfo/
- create file Definition.class.php in this new folder
<?php class SysInfo_Definition extends Gpf_Plugins_Definition { public function __construct() { $this->codeName = 'SysInfo'; $this->name = 'Name of the plugin'; $this->description = 'Description of the plugin'; $this->version = '1.0.0'; // requirements, connection to extension points, .. -> will be explained later } } ?>Now you will see this plugin in list of plugins and you will be able to activate it. So far this plugin does not do anything.
Connecting plugin to the application
Plugin can connect to extension points in application or in other plugins. All application extension points are defined in:
- include/Gpf/Definition.class.php
- include/Pap/Definition.class.php (attached at the bottom of this article)
Extension points are defined in initDefines() method. e.g:
$this->addDefine('PostAffiliate.merchant.menu', 'Gpf_Menu');This defines extension point with name PostAffiliate.merchant.menu with context class Gpf_Menu. Context class will be explained later.
To connect plugin to extension point you need to insert following code to plugin Definition class constructor.
$this->addRequirement('PapCore', '4.0.4.10'); $this->addImplementation('PostAffiliate.merchant.menu', 'SysInfo_Main', 'addToMenu');PostAffiliate.merchant.menu extension point is defined in PapCore plugin so you should give it to plugin requirements.
$this->addImplementation connects plugin to the extension point. First parameter is name of extension point. Second argument is plugin handler class. Third argument is method which will be executed in this plugin handler.
Writing plugin handler class
Plugin handler class must extend Gpf_Plugins_Handler and implement getHandlerInstance() method.
class SysInfo_Main extends Gpf_Plugins_Handler { /** * @return SysInfo_Main */ public function getHandlerInstance() { return new SysInfo_Main(); } // .... }Writing method which will be triggered on extension point
In previous sections we have created plugin handler and declared that we want to trigger SysInfo_Main::addToMenu() on PostAffiliate.merchant.menu extension point. This extension point defines Gpf_Menu as its context class. Method SysInfo_Main::addToMenu() must accept parameter which class is Gpf_Menu.
// this method will be triggerred on PostAffiliate.merchant.menu extension point
public function addToMenu(Gpf_Menu $menu) {
// execute any code, modify $menu, ...
}
In this example we want to add item to merchant menu which will display third party application in merchant panel menu.
public function addToMenu(Gpf_Menu $menu) { $url = 'urlPage;{"url":"' . Gpf_Paths::getInstance()->getBaseServerUrl() . 'plugins/SysInfo/phpsysinfo/' . '", "openType":"P"}'; $menu->getItem('Tools')->addItem($url, 'System Information'); }