2017-03-26 |  admin
GB flag PL flag

Plugins

Altego has a possibility to extend core functions by building own plugins.
Be carefull! From version 2.0.55, the path of plugins has been changed to application/ third_party/ res/ plugins/. Read more in change log.

First You need to create a folder in application directory and name it starting from "plg_".

for example: Plg_slider

It is information for system and front's users about source of used module.

Inside new folder You can place any files like controller, models, views or configs helpers etc. It is a HMVC pattern so every new module/plugin means for Altego something like new application.

Remember! Altego uses a HMVC pattern in building solution.

In folders must be at least two files with the valid name patterns: Your_plugin_slum_name and Your_plugin_slum_name_core.

These two files also must be in controller directory and must contains valid content.

Creating class with the hooks actions

The first file must be named like main folder but without "plg_" string.

In this pseudo-controller You can define a hook actions which are runs during the CMS works.

Class must extends Plg_run_controller, and for example it's can look like:

class Morris extends Plg_run_controller

That all what You need to do. If You won't use any hooks - just leave this class extending the parent and don't forget to initialize a parent __construct () method.

But ussually You will add the hooks and others actions so take I look how easy it is in Altego:

Adding CSS/JS

To simple add some JS or CSS files just use a valid method add_js() or add_css(). It's will inform a core about expected files in public_html/plugins/Your_plugin_name/css_or_js_path/ and finally will include them.

Adding a custom action

If You wish to create an action with Your own code then You have to implement a add_action() method with two parameters:

add_action ($action_name, $method_name)

$action_name is a constant where hook will be released. Now we have the followings:

Collapse list

  1. PRE_CONTROLLER
  2. POST_CONTROLLER_CONSTRUCTOR
  3. POST_CONTROLLER
  4. POST_SYSTEM
  5. PRE_OUTPUT
  6. POST_OUTPUT
  7. PRE_ARTICLE
  8. ARTICLE
  9. POST_ARTICLE
  10. PRE_MENU
  11. POST_MENU
  12. PRE_FOOTER
  13. FOOTER
  14. POST_FOOTER
  15. PRE_BODY
  16. POST_BODY
  17. HEAD
  18. META
  19. CSS
  20. JS
  21. POST_USER_LOGIN
  22. DASHBOARD

The string PRE means before and POST means after some section. You need just to test it (describe will appear soon).

$method_name is a name of an action to run in correct order, inside Your class. For example if You want to run action my_code() in CSS (CONSTANT) type:

$this->add_action (CSS, 'my_code);

Replacing a content

When You are going to replace some contents (by preg_replace or whatever) - then You need to call a method below:

add_filter ($method_name)

But be aware of using it! You always need to return a parsed output back. Otherwise no content will be displayed.

Public sources

You might want to use other sources like images, scripts etc. Simply create the path in public_html/plugins/Your_plugin_slum/img_or_whatever. You can organise it as You wish and use by actions methods mentioned before.

Creating a file with information

The second file is much easier to create. You simply need to create class extending Plg_core_controller, and pass an array with required fields by __construct() method for example:

if (!defined ('BASEPATH'))
	exit ('No direct script access allowed');
/*
 * EXAMPLE OF PLUGIN CLASS CONFIGURATION
 */

class Morris_core extends Plg_core_controller
{

	// __construct

	function __construct ()
	{
		// konfiguracja

		$cfg ['title'] = 'Morris';
		$cfg ['author'] = 'Olly Smith';
		$cfg ['version'] = 1;
		$cfg ['front'] = 0;
		$cfg ['admin'] = 1;
		$cfg ['status'] = 1;
		$cfg ['www'] = 'http://morrisjs.github.io/morris.js/';
		$cfg ['description'] = 'Powerfull charts.';
		$cfg ['order'] = 4;
		$cfg ['type'] = PLG_SYSTEM;

		// uruchomienie

		parent::__construct ($cfg);
	}

}

You can also do all what You wish directly after instalation or uninstalation. To do it just override methods install and uninstall. Before You call parent::method_name (), place all Your instructions.

Final

When You finish Your plugin then is a need to "compile" it to an .zip archive. To do it - press plugin > generate and find a plugin, after this press submit. Later You should install a plugin by selecting a generated zip in plugin > install.

Files

# File name Size Count download Description Created Modification Actions
1. plg_yourslum.rar 1.1 KB 1 Example file of Plugin usage.  2017-04-08 22:56  2017-04-08 22:57