Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Elgg 1.8 Social Networking

You're reading from   Elgg 1.8 Social Networking Create, customize, and deploy your very own social networking site with Elgg with this book and ebook

Arrow left icon
Product type Paperback
Published in Feb 2012
Publisher Packt
ISBN-13 9781849511308
Length 384 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Cash Costello Cash Costello
Author Profile Icon Cash Costello
Cash Costello
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Elgg 1.8 Social Networking
Credits
Foreword
About the Author
About the Author of 1st edition
About the Reviewers
www.PacktPub.com
Preface
1. Social Networking and Elgg FREE CHAPTER 2. Installing Elgg 3. A Tour of Your First Elgg Site 4. Sharing Content 5. Communities, Collaboration, and Conversation 6. Finding and Using Plugins 7. Creating Your First Plugin 8. Customization through Plugins 9. Theming Elgg 10. Moving to Production Developer's Quick Start Guide Views Catalog Index

Plugins


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 (http://community.elgg.org/) and Elgg's Github site (https://github.com/Elgg).

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.

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.

Conventions

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:

/mod/blog/views/default/
                        /blog/
                              /sidebar/
                                       /css.php
                                               /group_module.php

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image