Classes and Methods Using e107's built-in classes and methods.

Retrieving the database class object

$sql = e107::getDb();


Selecting data from a database table:

$sql = e107::getDb();
$sql->select('tablename', 'field1, field2', 'field_id = 1');


Selecting, looping through and displaying selected data with the fetch() method:

$sql = e107::getDb();
$sql->select('tablename', 'field1, field2', 'field_id = 1');
while($row = $sql->fetch())
    echo $row['field1'];


Inserting data into a database table:

$insert = array(
    'user_id' => 1,
    'user_email' => '@'

$sql->insert('user', $insert); // where 'user' is the table name


Updating information in a database:

$update = array(
    'user_email' => '@',
    // ... Long list of fields/values
    'WHERE' => 'user_id = 1'

$sql->update('user', $update); // where 'user' is the table name.


Combined select() and fetch() method.

Example: Get single value

$string = $sql->retrieve('user', 'user_email', 'user_id=1');

Example: Get multiple table-row values

if($allRows = $sql->retrieve('user', 'user_name, user_email', '', true))
	foreach($allRows as $row)
		echo $row["user_name"]." - ".$row["user_email"]."<br/>";  


Delete a record from a database table.

$sql->delete("user", "user_id=2");


Generic query function

Example: perform a JOIN with gen():

$sql->gen("SELECT f.*,u.user_name FROM #faqs AS f LEFT JOIN #users as u ON f.faq_author = u.user_id ");

Retrieving the form class object

$frm = e107::getForm();



Returns a form opening tag.

$frm->open('myform'); // returns
$frm->open('myform', 'get', 'myscript.php', array('autocomplete' => 'on', 'class' => 'formclass'));

Name Description
$name string - form name
$mode string - post | get - 'post' by default
$target string - request URL - e_REQUEST_URI by default
$options array - specify options such as class or autocomplete


Returns a form closing tag

$frm->close(); // returns </form>


Returns a text field form element

$frm->text('my-field', 'current_value', 100, array('size' => 'large')); // returns <input class="tbox input-large" id="my-field" maxlength="100" name="my-field" type="text" value="current_value"></input>

Name Description
$name string - name of the text field
$value string - value of the text fieldt
$maxlength integer - specifies maxlength element of the text field
$options array - specify options such as class, size or selectize
size: mini, small, medium, large, xlarge, xxlarge
selectize: array with selectize.js options














carousel() Render a Bootstrap carousel

$frm->carousel($name, $array, $options);
$array = array(
      'slide1' => array('caption' => 'Slide 1', 'text' => 'first slide content' ),
      'slide2' => array('caption' => 'Slide 2', 'text' => 'second slide content' ),
      'slide3' => array('caption' => 'Slide 3', 'text' => 'third slide content' )

echo $frm->carousel('my-carousel', $array);

tabs() Render Bootstrap tabs

$array = array(
   'home' => array('caption' => 'Home', 'text' => 'some tab content' ),
   'other' => array('caption' => 'Other', 'text' => 'second tab content' )

echo $frm->tabs($array);

echo $frm->tabs($array, array('active'=>'other')); // make 'other' the initial active tab. 


Parse HTML in various ways. eg. replace constants, convert bbcode etc.

$tp->toHtml(string, bbcodes, type);
$tp->toHtml("<strong class="bbcode bold bbcode-b bbcode-b-page">Bold print</strong>", true, 'BODY'); // Example
Name Description
string text or HTML to be parsed
bbcodes boolean - set to true to parse bbcodes into html


Convert a unix timestamp into a readable format.

$tp->toDate(unixDatestamp, format);
Format Description
short Short date format as defined in admin preferences
long Long date format as defined in admin preferences
relative Relative time format. eg. "2 days ago"


Convert html to plain text.



Convert e_xxxxx paths to their equivalent shortcodes. eg. e_PLUGIN becomes {e_PLUGIN}



Convert {e_XXXX} shortcode paths to their equivalent constants. eg. {e_PLUGIN} becomes e_PLUGIN



Parse an e107 template using core and/or custom shortcodes. ie. replaces all instances of {XXXXX_XXXX} etc.

$tp->parseTemplate(template, use core shortcodes, custom shortcodes);
Name Description
template string
user core shortcodes boolean
custom shortcodes object


Use to convert {e_MEDIA_IMAGE} and other image paths to an auto-sized image path for use inside an img tag.

$url = "{e_MEDIA_IMAGE}2012-04/someimage.jpg";
$image = $tp->thumbUrl($url);
echo "<img src='".$image."' />


Set the width, height and crop of the thumbUrl function.

$tp->setThumbSize($width, $height, $crop);


Convert a glyph name into Html. Just choose an icon from font-awesome and remove the first 'fa'
Templates may also use the following shortcode: which calls the same function.


Advanced settings:

$tp->toGlyph("fa-anchor", array('size'=>'2x'));


Render an icon. If a .glyph extension is found, it will automatically use the toGlyph() function above.

$iconPath = "{e_MEDIA}myicon.png";


Render a user avatar. If empty, the current user's avatar will be displayed if found or a generic avatar image.

echo $tp->toAvatar(); // render avatar of the current user. 
$userData = e107::user(5);  // Get User data for user-id #5. 
echo $tp->toAvatar($userData); // requires as a minimum $userData['user_image'].


Render an image.

$url = "{e_MEDIA_IMAGE}2012-04/someimage.jpg";
$parms = array('w'=>500, 'h'=>200,'crop'=>1, 'alt'=>'my image'); // if not width/height set, the default as set by {SETIMAGE} will be used.
echo $tp->toImage($url,$parms); 
Send HTML to the browser.

$ns = e107::getRender();
$ns->tablerender($caption, $text, $mode, $return);

Name Description
$caption string - header/caption
$text string - main content
$mode unique name for what is being rendered. eg contact-menu
$return boolean - when set to true the content is returned instead of being echoed.
Developers may retrieve admin preferences for their theme or plugin, or a core preference using the following method:

e107::pref(type, value);

Example: Load a stored value that was saved in the preferences admin area of the 'faqs' plugin

$myprefs = e107::pref('faqs'); // returns an array.

Or load a single preference value.
$perPage = e107::pref('faqs', 'faqs_per_page');

Type Value (optional)
core all core preference values.
theme preferences of the currently selected front-end theme.
(any plugin folder name) preferences of a particular plugin


Including javascript in your plugin or theme may be achieved by using the following function:

e107::js(type, value, dependency, zone);

Example: Load a script in the 'faqs' plugin directory and auto-load jquery if not already loaded.

e107::js('faqs','js/faqs.js', 'jquery')

Example: Load a theme script in the footer

e107::js("theme", "js/scripts.js", 'jquery');  // no 'zone' value, loaded in the footer by default. 

Example: Load a theme script in the header

e107::js("theme", "js/scripts.js", 'jquery', 2); // including a 'zone' value loads it in the header 
Type Value Description
core path relative to the core folder Include a core js file in the header of the page
url full url to javascript filel Include a remote js file in the header of the page
inline javascript code Include raw javascript code in the header of the page
theme path to js file, relative to the current theme's folder Include a theme js file
(any plugin folder name) path to js file, relative to the plugin's folder Include a plugin js file
settings ‡ array (PHP) Adds settings to e107's global storage of JavaScript settings.

settings: An associative array with configuration options. The array is merged directly into e107.settings. All plugins should wrap their actual configuration settings in another variable to prevent conflicts in the e107.settings namespace. Items added with a string key will replace existing settings with that key; items with numeric array keys will be added to the existing settings array.

JavaScript Behaviors

Behaviors are event-triggered actions that attach to page elements, enhancing default non-JavaScript UIs. Behaviors are registered in the e107.behaviors object using the method 'attach' and optionally also 'detach' as follows:

var e107 = e107 || {'settings': {}, 'behaviors': {}};

(function ($)
  e107.behaviors.myBehavior = {
    attach: function (context, settings)

    detach: function (context, settings, trigger)


e107.attachBehaviors is added to the jQuery ready event and so runs on initial page load. Developers implementing Ajax in their solutions should also call this function after new page content has been loaded, feeding in an element to be processed, in order to attach all behaviors to the new content.

See the e107_web/js/core/all.jquery.js file for more information.

Using jQuery

jQuery is now namespaced to avoid conflicts with other Javascript libraries such as Prototype. All your code that expects to use jQuery as $ should be wrapped in an outer context like so.

(function ($) {
  // All your code here.

If you don't, you may see the error Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function or similar.

jQuery Once

e107.behaviors will often be called multiple times on a page. For example, core/custom plugin performs some Ajax operation, all e107 behaviors will be executed again after page load, in order to attach any relevant JavaScript to the newly loaded elements. This can have the undesired affect of applying JavaScript to elements each time e107 behaviors are executed, resulting in the same code being applied multiple times. To ensure that the JavaScript is applied only once, we can use the jQuery $.once() function. This function will ensure that the code inside the function is not executed if it has already been executed for the given element.

Using jQuery $.once() (integrated into e107 core), the developer experience of applying these effects is improved. Note that there is also the $.removeOnce() method that will only take effect on elements that have already applied the behaviors.

var e107 = e107 || {'settings': {}, 'behaviors': {}};

(function ($)

  e107.behaviors.myBehavior = {
    attach: function (context, settings)
      $(context).find(".some-element").once('my-behavior').each(function ()
        // All your code here.


Settings passed locally to JavaScript Behaviors

e107.behaviors.myBehavior = {
  attach: function(context, settings) {
    $('#example', context).html(settings.myvar);

How to override a JavaScript Behavior

If you want to override a bit of core (or third party) e107 JavaScript Behavior, just copy the behavior to your javascript file (e.g in your plugin or theme), then load it after the original code using "zones".

Including css in your plugin or theme may be achieved by using the following function:

e107::css(type, value);

Type Value Description
theme path relative to the theme's folder Include a theme css file in the header of the site
url full url to css filel Include a remote css file in the header of the site
inline css code Include raw css code in the header of every page of the site

Returns an array of user data for the currently logged in user or another user if user_id is not null.

$userData = e107::user(); // Example - currently logged in user. 
$userData = e107::user(5); // Example  User ID #5.

Include meta tags in the html header.

e107::meta($name, $content, $extended);
e107::meta('keywords','some words'); // example
e107::meta('apple-mobile-web-app-capable','yes'); // example


Plugin developers can hook into various e107 core events and trigger functions of their own. Typically, an e_module.php file is used to store this information since it is loaded with every page.

Variable Description
name The event you wish to hook into. (see table below)
function Your function or class/method to trigger when this event occurs. string for function, or for classes use an array(class,method) .
include include[/code] (optional) path a file to include if required.

e107::getEvent()->register(name, function, include);

Example 1: trigger myFunction() on user login.

e107::getEvent()->register('login', 'myFunction'); 

function myFunction($data)
   // do something    

Example 2: trigger myFunction() on user login. Function in external file.

e107::getEvent()->register('login', 'myFunction',  e_PLUGIN."myplugin/myFunctions.php");

Example 3: trigger a class and method on user login.

e107::getEvent()->register('login', array('myClass', 'myMethod'),  e_PLUGIN."myplugin/myClass.php");

User Event Triggers

Trigger Name Description Data
login User login/signin Array of user data
logout User logout/signout Notice event
user_file_upload User uploads a file Array of file information
user_signup_submitted User submits signup form Array of user data
user_signup_activated User activates newly created account. (email link) Array of user data
user_xup_login User signs in via a social media account. eg. Facebook, Twitter etc. Array of user data
user_xup_signup User creates an account using their social media login. Facebook, Twitter etc. Array of user data
user_profile_display User has viewed a profile Array of data
user_profile_edit User has edited their profile Array of data

Custom page

Trigger function Description Data
user_page_item_viewed User has viewed a custom page Array of data


Trigger Name Description Data
user_news_item_viewed User viewed a news item Array of data
user_news_submit User submitted a news item Array of data

Private Messenger

Trigger name Description Data
user_pm_sent User has sent a private message Array of data
user_pm_read User has read a private message Array of data


Trigger Name Description Data
user_forum_topic_created User creates a forum topic Array of data
user_forum_topic_updated User updates a forum topic Array of data
user_forum_topic_deleted User deletes a forum topic Array of data
user_forum_post_created User creates a forum post/reply Array of data
user_forum_post_updated User updates a forum post/reply Array of data
user_forum_post_deleted User deletes a forum post/reply Array of data


Trigger function Description Data
user_chatbox_post_created User has posted a chatbox message Array of data (ip and message)

Admin Event Triggers

Admin changes their password

Trigger Name Description Data
admin_password_update Admin updates their password Array containing user_id and time of change.

Comments Manager

Trigger Name Description Data
admin_comment_update Admin updates a comment Array of comment data
admin_comment_delete Admin deletes a comment Array of comment data


Trigger Name Description Data
admin_download_create Admin creates a download item Array of download data
admin_download_update Admin updates a download item Array of download data
admin_download_delete Admin deletes a download item Array of download data


Trigger Name Description Data
admin_news_create Admin creates a news item Array of news data
admin_news_update Admin updates a news item Array of news data
admin_news_delete Admin deletes a news item Array of news data
admin_news_category_create Admin creates a news category Array of news data
admin_news__category_update Admin updates a news category Array of news data
admin_news_category_delete Admin deletes a news category Array of news data


Trigger Name Description Data
admin_page_create Admin creates a page/menu item Array of page data
admin_page_update Admin updates a page/menu item Array of page data (new and old)
admin_page_delete Admin deletes a page/menu item Array of page data


Trigger Name Description Data
admin_user_create Admin creates a new user Array of user data
admin_user_update Admin modifies user data Array of user data (new and old)
admin_user_delete Admin deletes a user Array of user data
admin_user_activate Admin activates an unverified user Array of user data
admin_user_loginas Admin logs in as another user Array of user data
admin_user_logoutas Admin logs out as another user Array of user data


You can assign and render 'alert' messages using the following.

<br />
$mes = e107::getMessage();


$mes = e107::getMessage();
$mes->addSuccess('You did it!');


$mes = e107::getMessage();
$mes->addError('There was a problem!');


$mes = e107::getMessage();
$mes->addWarning('You do not have access to this area!');


$mes = e107::getMessage();
$mes->addInfo('Please take note!');


Messages assigned here will only be displayed when debug mode is active.

$mes = e107::getMessage();
$mes->addInfo('Please take note!');


None of the above methods will output anything, until you use this method to render them.

$mes = e107::getMessage();
$mes->addInfo('Please take note!');
echo $mes->render();
You can log events to the admin system logs by using the built in log class.

$log = e107::getLog();


name a title or name for the log event.
details details for the log event - can be either a string of text or an array.
type the type of event. (see table below)
code is a custom reference code for your type of event. It should be short, ALL CAPITALS and not contain spaces.

$log = e107::getLog();
$log->add(name, details, type, code);

$log->add('My Event Name', $myDetailedData, E_LOG_INFORMATIVE, 'MYCODE');

Type Description
E_LOG_INFORMATIVE Informational event
E_LOG_NOTICE Notice event
E_LOG_WARNING Warning event
E_LOG_FATAL Fatal event


You can redirect to a url using the following static method:


To redirect to the home page, simply leave the url blank.


To redirect to the admin area, use the value 'admin'.


For any other location, include the full url.


You can generate a search-engine-friendly URL (where supported) using the following method:

e107::url(plugin, key, row, options);
Value Type Description
plugin string Folder name of the plugin. (will use data from e_url.php)
key string Unique key
row array array of variable data such as id, title etc. eg. user_id, user_name
options array An associative array of additional options, with the following elements:
'mode': abs | full
'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.


In this example we will generate a search-engine-friendly URL for a forum topic with the following code: .

$data = array(
); // these values are usually loaded from the database.

$url = e107::url('forum','topic',$data);

The code above loads the following file: e107_plugins/forum/e_url.php and generates a URL from the following array data with the unique key topic:

$config['topic'] = array(
'regex' => '^forum/(.*)/(d*)-([w-]*)/???(.*)',
'sef' => 'forum/{forum_sef}/{thread_id}-{thread_sef}/',
'redirect' => '/e107_plugins/forum/forum_viewtopic.php?id=$2&$4'

Only the value of 'sef' is used in this array. it substitutes the values {forum_sef}, {thread_id} and {thread_sef} with the variables in the $data array.

The end result would look something like this: