Lightnote CMS - web 2.0 content management system

Getting started

Extensions are custom PHP modules which you can integrate into your website. There are located in /extensions/[EXTENSION_NAME] directory. Name of extension can contain only alphanumeric characters (a-z, 0-9) and underscore (_).

Each extension must consist of at least 2 files:

  1. PHP Class named Ext_[EXTENSION_NAME] and placed into class.ext_[EXTENSION_NAME].php file.
  2. Configuration file: config.xml (XML Configuration file).

As mentioned in Page Templates section, it is very important to save all your template files in UTF-8 encoding to avoid many problems associated with inappropriate display of special characters.

Configuration (config.xml)

Most developers will not need to manually author complete Configuration file of their extensions. Rather, the majority of this task will (thankfully) be relegated to Extension Wizard, which you can find in Administration section of Lightnote CMS. Once the configuration file has been generated, you can go in and fine-tune XML definitions by hand if necessary.

While Extension Wizard can generate a good deal of Extension's configuration on your behalf, it is important for you to understand the basic XML syntax.

<?xml version="1.0" encoding="utf-8"?>
<Extension>
   <friendlyName>Sample extension</friendlyName>
   <author>Dmitry Monin</author>
   <version>1.0</version>
   <description>Here goes the description.</description>
</Extension>
NodeName Level Required Description
Extension 1 Yes Root Node
friendlyName 2 Yes Name of extension which will be shown in CMS Backend.
author 2 No Author of template.
version 2 No Version of template.
localConfig 2 No Configuration of extension's parameters applicable to each instance of extension separately.
globalConfig 2 No Configuration of extension's parameters applicable to all instances of extension.
database 2 No Database configuration.

PHP Class

All extensions ultimately derive from a common base class named Extension. Extension in turn derives from PageContent class. PageContent and Extension each define a number of fields and methods common to all extensions.

Key Members of the Extension class.

Member Description
id Unique id of extension's content element.
lang Language code of content element, you may need to use it for localisation purposes.
templatesPath Path to templates directory (relative to extension directory). By default it is empty string, what is equal to extension path.
Assign($key, $value) Assigns smarty variable. Benefit of using this method is that all assigned variables will be cleaned after extension's render.
Fetch() Returns the template output.
GetGlobalControls Returns an associative array of extension's global controls objects (defined in globalConfig section, in config.xml).
GetGlobalVars Returns an associative array with values of global controls.
GetLocalControls Returns an associative array of extension's local controls objects (defined in localConfig section, in config.xml).
GetLocalVars Returns an associative array with values of local controls.
Render() Method called by CMS during page render, which must return extension's content.

"Hello world!" example

Let's consider simpliest extension which outputs "Hello world!".

First, create a new folder inside extensions folder and name it "hello_world". Now, create 2 files inside of this folder: config.xml and class.ext_hello_world.php.

config.xml
<Extension>
    <friendlyName>Hello World</friendlyName>
</Extension>
class.ext_hello_world.php
<?php
class Ext_hello_world extends Extension
{
    function Render()
    {
        return "Hello world!";
    }
}
?>

That's it. Now you must be able to see your extension in Administration > List of extensions. Click Install and than finish installation by clicking install again (without specifying any additional parameters).

Screenshot

Now go to Page Browser, add just created extension on some page and test it.

Adding a template

Let's add to our "Hello world" extension a smarty template file. Create a file named template.html within your extension directory.

template.html
Hello world.<br />
Today is {$date}.
And change class.ext_hello_world.php to the following:
<?php
class Ext_hello_world extends Extension
{
    function Render()
    {
	$this->Assign("date", date("d.m.Y"));
	$content = $this->Fetch("template.html");
        return $content;
    }
}
?>