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
Credits
Foreword
About the Author
About the Author of 1st edition
About the Reviewers
www.PacktPub.com
Preface
Index

A Model-View-Controller perspective of Elgg


This section provides an overview of Elgg through the lens of the MVC pattern.

Overview

It all starts with a request. The most common scenario is a web browser requesting an HTML page. Let's assume it is a request for the web page that displays Joe's latest vacation photos. The request arrives at the controller. The controller confirms that Joe exists as a user at the site. It tells the model to increment the view counter on the photo album. The controller then passes the album identifier over to the view for rendering. The view pulls the photo objects from the model and creates the HTML page that is sent to the web browser.

Controllers

Elgg uses the Front Controller pattern with a twist. In the Front Controller pattern, every request is routed through a single controller. This is unlike web applications that use individual scripts to handle different types of requests (for example, logging in uses login.php, posting a comment uses post-comment.php, and so on). The twist with Elgg's implementation of this pattern is that it has two primary front controllers. One front controller handles actions, which usually involve the submission of a form. The other front controller handles requests for pages, which are most often HTML pages.

The job of the front controller is loading the framework and dispatching the request to the appropriate secondary controller. A page controller processes the parameters of the request, updates the data model, and turns the processed request over to the views system. An action controller is similar except that it does not turn a request over to the views system, but instead forwards the requester to a new page. In Elgg, these controllers are called handlers.

The following diagram shows request processing logic inside the controller box of the overview diagram. The diagram includes three of the page handlers provided by plugins as examples of secondary controllers.

The two primary handlers are located at /engine/handlers/.

Model

The model of Elgg consists of three parts:

  1. Data model classes that manage entities, metadata, and relationships.

  2. Helper functions that build queries based on parameters (give me the 10 latest blog posts written by Bob).

  3. Database access layer that provides an interface to the MySQL database.

The data model supports a wide range of use cases because of its simple and flexible design. Developers should use Elgg's data model rather than writing their own queries or creating their own tables.

Views

The views system renders data into HTML (or other formats such as RSS). It has two steps. In the first step, the controller requests the view system to render the data from the model for presentation. In the second step, this output is inserted into a layout and the complete response is rendered. This is different from frameworks that use a per page template that lays out an entire page. An advantage of the two step approach is the ease of maintaining a consistent look across all pages.

The output from the first step is represented by the content box in the following diagram. The second step handles the remaining sections of a page.

Both steps use templates which are called views in Elgg. Views are short scripts that provide building blocks for creating web pages and other types of output. In the preceding diagram, the topbar, header, sidebar, and footer are created by views. As mentioned earlier, PHP is the template language used in the views.

Each request has a view type that determines the response format. If the view type is default, then an HTML page is created. If it is json, then the same data is rendered in JSON format. The view type is set by the controller based on the parameters of the request. This view type functionality can be used to serve a mobile-specific layout to mobile devices. An example of this can be found in Chapter 9.