Extending core functionality (addons)

Please note: This page is under construction and has not been finished yet.

Introduction

There are several ways to extend the core functionality of e107. One of those ways is by using so-called "addons". These addons are files which reside in each plugin's folder and allow a plugin to embed itself inside e107's core pages and functions.

The addons can be recognised by their e_xxxxx.php naming format. By simply placing them inside your plugin's folder, they will be auto-detected during installation and integrated into the system.

TIP: The _blank plugin in the e107_plugins folder contains example addons that may be an easy reference for you.

Overview of all plugin addons

Plugin addons

e_admin.php

TODO: Add example. See social plugin for an example.

e_bb.php

TODO: Add example.

e_comment.php

TODO: Add example. See social plugin for an example.

e_cron.php

This addon allows a plugin to add additional scheduled task options to e107. (see Admin Area > Tools > Scheduled Tasks).

Example:

class plugindir_cron   // plugin-folder name + '_cron'
{
    function config() // Setup  
    {
        $cron = array();
	
        $cron[] = array(
            'name'            => "Name of my function",  // Displayed in admin area. . 
            'function'        => "myFunction",    // Name of the function which is defined below. 
            'category'        => 'mail',           // Choose between: mail, user, content, notify, or backup
            'description'     => "Description of what my function does"  // Displayed in admin area. 
        );		
		
        return $cron;
    }
	
    public function myFunction()
    {
        // Do something. 
    }

}

e_dashboard.php

This addon adds custom plugin information to the dashboard of e107's admin area. The 'latest', 'status' and 'website stats' areas may all contain information from your plugin.

Previously, the e_latest and e_status addons were used separately for this. They have now been incorporated into the e_dashboard addon.

Example:

class plugindir_dashboard // plugin-folder name + '_dashboard'
{
	private $title; // dynamic title.
	
	function chart()
	{
		$config = array();

		$config[] = array(
			'text'		=> $this->activity(),
			'caption'	=> $this->title,
		);

		return $config;
	}

	/**
	 * Non-functional example.
	 */
	function activity()
	{
		// do something
	}
		
	function status() // Status Panel in the admin area
	{
		$var[0]['icon'] 	= "<img src='".e_PLUGIN."plugindir/images/blank_16.png' alt='' />";
		$var[0]['title'] 	= "My Title";
		$var[0]['url']		= e_PLUGIN_ABS."plugindir/plugin.php";
		$var[0]['total'] 	= 10;

		return $var;
	}	
	
	function latest() // Latest panel in the admin area.
	{
		$var[0]['icon'] 	= "<img src='".e_PLUGIN."plugindir/images/blank_16.png' alt='' />";
		$var[0]['title'] 	= "My Title";
		$var[0]['url']		= e_PLUGIN_ABS."plugindir/plugin.php";
		$var[0]['total'] 	= 10;

		return $var;
	}	
}

e_emailprint.php

Deprecated! This addon has been deprecated. Use e_print.php instead.

e_event.php

This addon allows a plugin to easily hook into system events and trigger their own methods and functions using data provided by those events.

You can make use of the event methods and event triggers.

Example:

class plugindir_event // plugin-folder + '_event'
{
	function config()
	{
		$event = array();		

		// Hook into a core event, in this case "login". 
		$event[] = array(
			'name'		=> "login", // when this is triggered... 
			'function'	=> "myfunction", // ..run this function (see below).
		);
		
		// Hook into a custom plugin event (created by that plugin author)
		$event[] = array(
			'name'		=> "pluginfolder_customevent", // hook into a custom plugin event
			'function'	=> "otherfunction", // ..run another function (see below).
		);

		return $event;
	}

	function myfunction($data) // the method to run.
	{
		// var_dump($data);
	}
	
	function otherfunction($data) // the method to run.
	{
		// var_dump($data);
	}
}

e_featurebox.php

TODO: Add example.

e_footer.php

This addon allows a plugin to include code in the footer of every page of the site.

Please find an example in the "tinymce4" plugin.

e_frontpage.php

Example:

class plugindir_frontpage // plugin-folder + '_frontpage'
{
	// Option 1: individual item
	function config()
	{

		$frontPage = array(
			'page' 	=> '{e_PLUGIN}_blank/_blank.php', 
			'title' => LAN_PLUGIN__BLANK_NAME
		);

		return $frontPage;
	}

	
	// Option 2: multiple items
	function config()
	{
		$config = array();

		$config['title']    = LAN_PLUGIN__BLANK_NAME;
		$config['page']     = array(
			0   => array(
				'page' => '{e_PLUGIN}_blank/_blank.php', 
				'title'=>'Main Page'
			),
		);

		return $config;
	}
}

e_gsitemap.php

TODO: Add example. See "news" plugin folder for an example.

e_header.php

This addon allows a plugin developer to add data to the <head> of every page. This file is loaded in the header of each page of your site. ie. Wherever you see require_once(HEADERF) in a script. Typically you would use one or all of the following functions within this file: e107::js(), e107::css() or e107::meta()

Warning: Output should never be echoed or printed from this file!

Example:

if(deftrue('USER_AREA')) // prevents inclusion of JS/CSS/meta in the admin area.
{
	e107::js('_blank', 'js/blank.js');      // loads e107_plugins/_blank/js/blank.js on every page.
	e107::css('_blank', 'css/blank.css');    // loads e107_plugins/_blank/css/blank.css on every page
	e107::meta('keywords', 'blank,words');   // sets meta keywords on every page.
}

e_help.php

Deprecated! This addon allowed plugin developers to add information to the plugin configuration page sidebar. This has now been integrated within the Admin-UI through the renderHelp() method.

e_latest.php

Deprecated! This addon has been deprecated. Use e_dashboard.php instead.

e_library.php

Please find an example in the "_blank" plugin.

e_linkgen.php

Deprecated! This addon has been deprecated. Use e_sitelink.php instead.

e_list.php

TODO: Add example.

e_mailout.php

This addon allows a plugin to use e107's mailout feature for bulk mailing.

Please find an example in the "newsletter" plugin.

e_menu.php

This addon provides configuration options for each instance of the plugin's menus.

The e_menu.php addon is a replacement for the old config.php file used in e107 v1.x.

Example:

class plugindir_menu // plugin-folder name + '_menu'
{
	function __construct()
	{
		
	}

	/**
	 * Configuration Fields. 
	 * See Admin-UI field configurations (https://devguide.e107.org/plugin-development/admin-ui)
	 * @return array
	 */
	public function config($menu='')
	{
		$fields = array();
		$fields['blankCaption'] 	= array('title' => "Caption", 'type' => 'text', 'multilan'=>true, 'writeParms'=>array('size'=>'xxlarge'));
		$fields['blankCount']		  = array('title' => "Enabled", 'type' => 'number');
		$fields['blankCustom']		= array('title' => "Enabled", 'type' => 'method'); // see below.

    return $fields;
	}
}

// optional - for when using custom methods above.
class plugindir_menu_form extends e_form
{
	function blankCustom($curVal)
	{
		$frm 	  = e107::getForm();
		$opts 	= array(1, 2, 3, 4);

		$frm->select('blankCustom', $opts, $curVal);
	}
}

e_meta.php

Deprecated! This addon has been deprecated. Use e_header.php instead.

e_module.php

This addon is loaded every time the core of e107 is included. ie. Wherever you see require_once("class2.php") in a script.

It allows a developer to modify or define constants, parameters etc. which should be loaded prior to the header or anything that is sent to the browser as output. It may also be included in Ajax calls.

e_notify.php

Example:

class plugindir_notify extends notify // plugin-folder name + '_notify' 
{		
	function config()
	{	
		$config = array();
	
		$config[] = array(
			'name'			=> "New Trigger Name", // Displayed in admin area. 
			'function'		=> "plugindir_mytrigger",
			'category'		=> ''
		);	
		
		return $config;
	}
	
	function plugindir_mytrigger($data) 
	{
		$message = print_a($data,true);
		
		$this->send('plugindir_mytrigger', "My Subject", $message);
	}
}

The notification can then be triggered by using:

e107::getEvent()->trigger("plugindir_mytrigger", $data);

e_output.php

e_parse.php

This addon allows to hook into e107's parser methods

Example:

class plugindir_parse // plugin-folder name + '_parse' 
{
	/**
	 * Process a string before it is sent to the browser as html.
	 * @param string $text html/text to be processed.
	 * @param string $context Current context ie.  OLDDEFAULT | BODY | TITLE | SUMMARY | DESCRIPTION | WYSIWYG etc.
	 * @return string
	 */
	function toHTML($text, $context = '')
	{
		$text = str_replace('****', '<hr>', $text);
		return $text;
	}


	/**
	 * Process a string before it is saved to the database.
	 * @param string $text html/text to be processed.
	 * @param array $param nostrip, noencode etc.
	 * @return string
	 */
	function toDB($text, $param = array())
	{
		$text = str_replace('<hr>', '****', $text);
		return $text;
	}
}

e_print.php

This addon allows a plugin developer to specify content that is displayed in printer-friendly format

Example:

class plugindir_print // plugin-folder + '_print'
{
	public function render($parm)
	{
		$text = "Hello {$parm}!"; 

		return $text;
	}	
}

e_rss.php

This addon adds the plugin to the RSS plugin, and generates RSS feeds for the plugin.

Example:

class plugindir_rss // plugin-folder name + '_rss'
{
	/**
	 * Admin RSS Configuration
	 */
	function config()
	{
		$config = array();

		$config[] = array(
			'name'			  => 'Feed Name',
			'url'			    => 'blank',
			'topic_id'		=> '',
			'description'	=> 'This is the RSS feed for the blank plugin', // that's 'description' not 'text'
			'class'			  => e_UC_MEMBER,
			'limit'			  => '9'
		);

		return $config;
	}

	/**
	 * Compile RSS Data
	 * @param array $parms
	 * @param string $parms['url']
	 * @param int $parms['limit']
	 * @param int $parms['id']
	 * @return array
	 */
	function data($parms=array())
	{
		$sql = e107::getDb();

		$rss = array();
		$i = 0;

		if($items = $sql->select('blank', "*", "blank_field = 1 LIMIT 0,".$parms['limit']))
		{
			while($row = $sql->fetch())
			{
				$rss[$i]['author']			  = $row['blank_user_id'];
				$rss[$i]['author_email']	= $row['blank_user_email'];
				$rss[$i]['link']			    = "_blank/_blank.php?";
				$rss[$i]['linkid']			  = $row['blank_id'];
				$rss[$i]['title']			    = $row['blank_title'];
				$rss[$i]['description']		= $row['blank_message'];
				$rss[$i]['category_name']	= '';
				$rss[$i]['category_link']	= '';
				$rss[$i]['datestamp']		  = $row['blank_datestamp'];
				$rss[$i]['enc_url']			  = "";
				$rss[$i]['enc_leng']		  = "";
				$rss[$i]['enc_type']		  = "";
				$i++;
			}

		}

		return $rss;
	}
}

e_related.php

This addon adds the plugin to the search which generates 'related' links in news items and pages of e107.

Example:

class plugindir_related // plugin-folder name + '_menu'
{
	function compile($tags,$parm=array()) 
	{
		$sql 	= e107::getDb();
		$items 	= array();
			
		$tag_regexp = "'(^|,)(".str_replace(",", "|", $tags).")(,|$)'";
		
		$query = "SELECT * FROM `#_blank` WHERE _blank_id != ".$parm['current']." AND _blank_keywords REGEXP ".$tag_regexp."  ORDER BY _blank_datestamp DESC LIMIT ".$parm['limit'];
			
		if($sql->gen($query))
		{		
			while($row = $sql->fetch())
			{

				$items[] = array(
					'title'			=> varset($row['blank_title']),
					'url'			=> e107::url('other',$row),
					'summary'		=> varset($row['blank_summary']),
					'image'			=> '{e_PLUGIN}_blank/images/image.png'
				);
			}
			
			return $items;
	    }
	
	}
}

e_search.php

This addon adds the plugin to the 'search page' of e107.

Example:

class plugindir_search extends e_search // plugin-folder name + '_search'
{
	function config()
	{	
		$search = array(
			'name'			=> "Blank Plugin",
			'table'			=> 'blank',

			'advanced' 		=> array(
								'date'	=> array('type'	=> 'date', 		'text' => LAN_DATE_POSTED),
								'author'=> array('type'	=> 'author',	'text' => LAN_SEARCH_61)
							),
							
			'return_fields'	=> array('blank_id', 'blank_nick', 'blank_message', 'blank_datestamp'),
			'search_fields'	=> array('blank_nick' => '1', 'blank_message' => '1'), // fields and weights.
			
			'order'			=> array('blank_datestamp' => 'DESC'),
			'refpage'		=> 'chat.php'
		);

		return $search;
	}

	/* Compile Database data for output */
	function compile($row)
	{
		preg_match("/([0-9]+)\.(.*)/", $row['blank_nick'], $user);

		$res = array();
	
		$res['link'] 		  = e_PLUGIN."blank_menu/_blank.php?".$row['blank_id'].".fs";
		$res['pre_title'] = LAN_SEARCH_7;
		$res['title'] 		= $user[2];
		$res['summary'] 	= $row['blank_message'];
		$res['detail'] 		= e107::getParser()->toDate($row['blank_datestamp'], "long");

		return $res;		
	}

	/**
	 * Optional - Advanced Where
	 * @param $parm - data returned from $_GET (ie. advanced fields included. in this case 'date' and 'author' )
	 */
	function where($parm=null)
	{
		$tp = e107::getParser();

		$qry = "";
		
		if (vartrue($parm['time']) && is_numeric($parm['time'])) 
		{
			$qry .= " blank_datestamp ".($parm['on'] == 'new' ? '>=' : '<=')." '".(time() - $parm['time'])."' AND";
		}

		if (vartrue($parm['author'])) 
		{
			$qry .= " blank_nick LIKE '%".$tp->toDB($parm['author'])."%' AND";
		}
		
		return $qry;
	}
}

e_shortcode.php

This addon allows a plugin to make their shortcodes available to core templates and templates of other plugins.

It's content is identical to that of a regular shortcode class except that all the methods must follow the following naming convention: sc_plugindir_name()

The $override property can be used to override existing core/plugin shortcodes. When set to true existing core/plugin shortcodes matching methods below will be overridden.

Example:

class plugindir_shortcodes extends e_shortcode
{
	public $override = false; // when set to true, existing core/plugin shortcodes matching methods below will be overridden. 

	// Example: {PLUGINDIR_CUSTOM} shortcode - available site-wide.
	function sc_plugindir_custom($parm = null)  // Naming:  "sc_" + [plugin-directory] + '_uniquename'
	{
		return "Hello World!";
	}
}

e_sitelink.php

This addon adds a sitelink sublink-generating function for your plugin. An example is auto-generated navigation drop-down menus for 'latest articles'.

Example:

class plugindir_sitelink // plugin-folder name + '_sitelink' 
{
	function config()
	{
		$links = array();	
		
		$links[]  = array(
			'name'        => 'Drop-Down MegaMenu',
			'function'    => 'megaMenu' // see method below
		);

		$links[] = array(
			'name'			  => "Drop-Down Links",
			'function'		=> "myCategories" // see method below
		);
	
		return $links;
	}
	

	function megaMenu() 
	{
		$text = '<div class="dropdown-menu mega-dropdown-menu">
                    <div class="container-fluid2">
                            <ul class="nav-list list-inline">
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                                <li><a data-filter="#" href="#"><img src="#><span>#</span></a></li>
                            </ul>
                    </div>
				</div>			
				';

		return $text;
	}

	function myCategories()
	{
		$sublinks 	= array();
		
		e107::getDb()->select("blank","*","blank_id != '' ");
		
		while($row = e107::getDb()->fetch())
		{
			$sublinks[] = array(
				'link_name'			    => e107::getParser()->toHTML($row['blank_name'],'','TITLE'),
				'link_url'			    => e107::url('_blank', 'other', $row),
				'link_description'	=> '',
				'link_button'		    => $row['blank_icon'],
				'link_category'		  => '',
				'link_order'		    => '',
				'link_parent'		    => '',
				'link_open'			    => '',
				'link_class'		    => e_UC_PUBLIC
			);
		}
		
		return $sublinks;
	}
}

e_status.php

Deprecated! This addon has been deprecated. Use e_dashboard.php instead.

e_tohtml.php

Deprecated! This addon has been deprecated. Use e_parse.php instead.

e_upload.php

TODO: Add example.

e_url.php

This addon provides a simple way to add mod-rewrite redirects to the plugin's pages, without having to edit the .htaccess file. This addon is used to create Search-Engine-Friendly (SEF) URLs through the e107::url() method.

Example:

TODO: add 'legacy' example and explanation

class plugindir_url // plugin-folder name + '_url' 
{
	function config() 
	{
		$config = array();

		$config['index'] = array(
			'regex'			  => '^_blank/?$', 						// matched against url, and if true, redirected to 'redirect' below.
			'sef'			    => '_blank', 							// used by e107::url(); to create a url from the db table.
			'redirect'		=> '{e_PLUGIN}_blank/blank.php', 		// file-path of what to load when the regex returns true.
		);

		$config['other'] = array(
			'alias'       => '_blank', 									// the below {alias} is substituted with this value. Default alias '_blank', w which can be customized within the admin area.
			'regex'			  => '^{alias}/other/?$', 						// matched against url, and if true, redirected to 'redirect' below.
			'sef'			    => '{alias}/other/', 							// used by e107::url(); to create a url from the db table.
			'redirect'		=> '{e_PLUGIN}_blank/_blank.php?other=1', 		// file-path of what to load when the regex returns true.
		);

		return $config;
	}
}

e_user.php

This addon allows to:

  • add information about a specific user to the user's profile page

  • add and save fields to the user configuration page (/usersettings.php)

  • specify a routine that is run upon user deletion

Example:

class plugindir_user // plugin-folder + '_user'
{		
	/**
	 * Display information on the user profile page 
	 */
	function profile($udata)  
	{

		$var = array(
			0 => array(
				'label' => "Label", 
				'text' 	=> "Some text to display", 
				'url'	  => e_PLUGIN_ABS."_blank/blank.php")
		);
		
		return $var;
	}

	/**
	 * This allows to show field on the usersettings.php page
	 * The same field format as admin-ui, with the addition of 'fieldType', 'read', 'write', 'appliable' and 'required' as used in extended fields table.
	 *
	 * @return array
	 */
	function settings()
	{
		$fields = array();

		$fields['field1'] = array(
			'title' 	   => "Field 1",  
			'fieldType'  => 'varchar(30)',  
			'read'		   => e_UC_ADMIN, 
			'write'		   => e_UC_MEMBER, 
			'type' 		   => 'text', 
			'writeParms' => array('size' => 'xxlarge')
		);

		$fields['field2'] = array(
			'title' 	   => "Field 2",  
			'fieldType'  => 'int(2)',       
			'type' 		   => 'number', 
			'data'		   => 'int'
		);

		$fields['field3'] = array(
			'title' 	  => "Field 3",  
			'fieldType' => 'int(1)',       
			'type' 		  => 'method', // see method below.
			'data'		  => 'str', 
			'required'	=> true
		); 

        return $fields;
	}

	/**
	 * This routine is run upon user deletion
	 * Experimental and subject to change without notice.
	 * @return mixed
	 */
	function delete()
	{

		$config['user'] =  array(
			'user_id'           => '[primary]',
			'user_name'         => '[unique]',
			'user_loginname'    => '[unique]',
			'user_email'        => '[unique]',
			'user_ip'           => '',
			// etc.
			'WHERE'             => 'user_id = '.USERID,
			'MODE'              => 'update'
		);

		$config['user_extended'] = array(
			'WHERE'             => 'user_extended_id = '.USERID,
			'MODE'              => 'delete'
		);

		return $config;
	}
}

// (plugin-folder)_user_form - only required when using custom methods.
class plugindir_user_form extends e_form
{
	// user_plugin_(plugin-folder)_(fieldname)
	public function user_plugin_plugindir_field3($curVal, $mode, $att = array())
	{
		$opts = array(1, 2, 3, 4);
		return $this->select('user_plugin_plugindir_field3', $opts, $curVal);
	}
}

Last updated