Writing a Portal Module

From EQdkp Plus
Jump to navigation Jump to search


This tutorial shows how to write a basic Portal Module that outputs some content.

Contents

Folder

The Portal Modules are located in the folder portal. Find a name for your new portal module, without special chars, space, etc., like "mynewportalmodule". Create a folder with the name of your new portal module, and create a subfolder called "language".

portal
- mynewportalmodule
- - language

Files

Create a file called "mynewportalmodule_portal.class.php" in the folder "mynewportalmodule". The Ending "_portal.class.php" is required. Create another file with your language name, like "english.php" in language subfolder of your module.

portal
- mynewportalmodule (Directory)
- - mynewportalmodule_portal.class.php (File)
- - language (Directory)
- - - english.php (File)

Portal Class

mynewportalmodule_portal.class.php

<?php
if ( !defined('EQDKP_INC') ){
	header('HTTP/1.0 404 Not Found');exit;
}

class mynewportalmodule_portal extends portal_generic {

	protected static $path		= 'mynewportalmodule'; //Same as the folder name
	
	protected static $data		= array(
		'name'			=> 'My New Portal Module',  //Name of the Module
		'version'		=> '2.0.1',					//Version of the Module
		'author'		=> 'GodMod',				//Author Name
		'icon'			=> 'fa-code',				//Icon showed at Portal Management. Class is from Font Awesome Icons
		'contact'		=> EQDKP_PROJECT_URL,		//Contact Email or Webpage 
		'description'		=> 'Output some content',//Little Description of what the module does
		'multiple'		=> true,					//Set to true if the module is clonable
		'mynewportalmodule'	=> 'mynewmod_'				//Prefix of Language, for Settings
	);
	protected static $positions = array('middle', 'left', 'right', 'bottom');	//Possible Possitions of the module
	
	//This Array Contains Settings For the Module
	protected $settings	= array(
		'useroutput'	=> array(
			'type'		=> 'textarea',
			'cols'		=> '40',
			'rows'		=> '8',
			'codeinput'	=> true,
		),		
	);

	//This is the API Level. See the API Level Section of Wiki Entry
	protected static $apiLevel = 20;

	//The Outout 
	public function output() {
		$output = "This is some output. <br /> And the following comes from the setting input: <br />";
		
		$output =  xhtml_entity_decode(htmlspecialchars_decode($this->config('useroutput')));
		return $output;
	}
}
?>

Language File

english.php

<?php
if ( !defined('EQDKP_INC') ){
	header('HTTP/1.0 404 Not Found');exit;
}

$lang = array(
	'mynewportalmodule'		=> 'My new Portal Module',
	'mynewportalmodule_name'	=> 'My new Portal Module',
	'mynewportalmodule_desc'	=> 'Output some content',
	//Settings
	'mynewportalmodule_f_useroutput'=> 'Enter the content to show',
);
?>

Settings

Available Setting Types:

  • bbcodeeditor
  • checkbox
  • colorpicker
  • datepicker
  • dropdown
  • file
  • filetree
  • hidden
  • imageuploader
  • int
  • multiselect
  • password
  • radio
  • slider
  • spinner
  • text
  • textarea
  • timepicker

Each Type has its own settings. For more information, take a look at the apropriate hTYPENAME.class.php in core/html/ - Folder of your EQdkp Plus.

API Level

With EQdkp Plus 2.0, we introduced an API Level for the Portal Class. This ensures, that the old Portal Modules cannot produce fatal errors if they use removed methods of the Portal Class. If we want to remove or rename Portal Class Methods, we set them as deprecated (can be viewn if Debug-Mode is enabled). After two Increasements of the API Level, we will remove the method. That means that Portal Modules will not work anymore and loaded by the EQDkp Plus if their API-Level is Recent API level minus three.

That means that an module author has to update it's module regularly to make sure his module is working with the latest API.

Example

We want to remove a method in API Level 19. We set this method as deprecated and increase the API Level to 20. With API Level 22, this method will be removed. All modules with an API Level lower 20 will not be loaded anymore and have to be adjusted to the new API Level.

API Levels

API-Level EQdkp Plus Version
20 2.0.0


Config

To access the saved values of your settings, use the config() method.

$this->config('useroutput');

Do not mix it up with the regular config class ($this->config->get('varname'))