Book Image

Elgg 1.8 Social Networking

By : Cash Costello
Book Image

Elgg 1.8 Social Networking

By: Cash Costello

Overview of this book

As an updated version of the first ever Elgg book, this is an excellent resource for those interested in Elgg development due to its attention to detail, clearly written style and knowledgeable author. - Dave Tosh, Elgg co-founder. In his book, Cash Costello makes full use of his skills in development and communication to tackle the complex subject of Elgg social networking. This easy-to-read guide gives end users, new developers, and old pros alike a solid base to start their venture into social media with Elgg. I highly recommend it as a useful and enjoyable read. - Brett Profitt, Elgg Lead Developer The web is becoming increasingly social as millions of people use it to blog, share, post, 'friend', 'unfriend' (which was made the Oxford word of the year in 2009), comment, and chat. Elgg ñ your award-winning open source social networking engine ñ is tailor-made to create any social networking or social media website you can imagine. If you want to create a social networking website from scratch using Elgg, then this book is exactly what you need.Elgg 1.8 Social Networking covers everything you need to know about building a social networking site with Elgg. It begins with instructions for installing Elgg, continues with a guided tour of its capabilities, and finishes with practical advice on deploying Elgg on a production server. And in between, it is packed with information on configuring and customizing Elgg through plugins and themes.This book is a learn-by-doing guide to creating your own social networking site. It includes three sample case studies on how Elgg could be used as an e-learning tool, an intranet application for organizations, and a niche social networking site. Step by step it takes you through the installation, configuration, and customization of Elgg. Valuable advice is sprinkled throughout the book to enable you to build your site like an expert. For developers, this book provides a multitude of options. First, there is a tutorial-based section that systematically teaches you how to build plugins. Soon you will have ten plugins for use on your site in addition to all the knowledge you have gained. Second, if you prefer a quick overview, this book has an appendix that describes Elgg using the terminology and design patterns common in web development. Third, if you are interested in creating a theme, it also includes a design tutorial and a catalog of Elgg's view templates. The book then goes on to describe what is involved in running a production website. It has sections on selecting a hosting provider, configuring and tuning the server, backing up the site, and dealing with spammers.
Table of Contents (21 chapters)
Elgg 1.8 Social Networking
About the Author
About the Author of 1st edition
About the Reviewers


The Elgg core does not do much by itself. It provides the foundation and the plugins determine what the web application truly does. Elgg is distributed with more than 30 plugins that are referred to as bundled plugins. Additional plugins are available from the Elgg community site ( and Elgg's Github site (

Plugins can add significant user-facing functionality or customize minor backend processing. They can override core functionality or extend it. Building a website with Elgg requires writing and using plugins. Chapter 7 and 8 provide a tutorial-based approach to learning to write plugins.

Plugins are installed in the /mod/ directory. Each directory in /mod/ is a plugin. Plugins are structured like mini versions of the Elgg core (though only the classes, languages, and views directories are required to have those names):

  • /actions

  • /classes

  • /graphics

  • /languages

  • /pages

  • /vendors

  • /views

  • start.php

  • manifest.xml

The manifest file describes the function of the plugin and this information is used on the plugin administration page. The start.php file is the boot script of the plugin. It registers callbacks, extends views, and performs other initialization.


When Elgg loads, it includes the start.php file of each activated plugin. In start.php, a plugin registers a handler for the 'system', 'init' event:

elgg_register_event_handler('init', 'system', 'blog_init');

This event is triggered when all of the core libraries and plugins have been loaded. It is in this event handler that the plugin does its initialization:

function blog_init() {

  elgg_extend_view('css', 'blog/css');

  elgg_register_page_handler('blog', 'blog_page_handler');

  // Register for search.
  elgg_register_entity_type('object', 'blog');

  $action_path = dirname(__FILE__) . '/actions/blog';
  elgg_register_action('blog/save', "$action_path/save.php");

This occurs before a request is dispatched to a handler (action or page handler).

Plugin order

Plugins can override views, actions, and language strings. If more than one plugin overrides the same view, then it is the plugin that loads last that has its view used. The same is true for anything else that can be overridden. The plugin order is set on the plugin administration page.


An important convention when writing plugins is namespacing the code to prevent conflicts with other plugins or future additions to the core framework.

Functions normally include the name of the plugin:

function blog_url_handler($entity) {

The same is true for language strings (described later in this guide):

'blog:revisions' => 'Revisions',

Views should be namespaced by creating a directory under the default directory named after the plugin:


Actions should also begin with the name of the plugin:

elgg_register_action('blog/save', "$action_path/save.php");

In addition to these naming conventions, there are Elgg coding standards included in the docs directory. These are the standards that the core developers follow.