Location: PHPKode > projects > OpenNitro > trunk/Nitro/Module.inc.php
<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Module                                                           |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2003-2006 June Systems BV                                   |
// +---------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify it   |
// | under the terms of the GNU Lesser General Public License as published by  |
// | the Free Software Foundation; either version 2.1 of the License, or (at   |
// | your option) any later version.                                           |
// |                                                                           |
// | This library is distributed in the hope that it will be useful, but       |
// | WITHOUT ANY WARRANTY; without even the implied warranty of                |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser   |
// | General Public License for more details.                                  |
// |                                                                           |
// | You should have received a copy of the GNU Lesser General Public License  |
// | along with this library; if not, write to the Free Software Foundation,   |
// | Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA            |
// +---------------------------------------------------------------------------+
// | Authors: Jesper Avot <hide@address.com>                             |
// +---------------------------------------------------------------------------+
//
// $Id: Module.inc.php 229 2008-04-17 09:20:31Z oli $
//

/**
 * This file contains the Nitro Module prototype class.
 * 
 * @author			Jesper Avot <hide@address.com>
 * @copyright		2006 June Systems BV
 * @package			Classes
 * @subpackage	NitroModule
 */
 
/**
 * Include required files
 */
include_once 'Nitro/NitroSettings.inc.php';

/**
 * Prototype Nitro module
 *
 * All modules used in Nitro should be derived from this prototype
 * module. This prototyp defines all the functions that can be called
 * on an installed module by Nitro. If a certain function is not defined
 * in the user module, the default defined in this class will be called.
 *
 * @package			Classes
 * @subpackage	NitroModule
 */
class NitroModule extends NitroSettings {
	/**
	 * Default module DB connection
	 */
	var $DB;
	/**
	 * Default module Session handler
	 */
	var $Sess;
	/**
	 * Default module configuration
	 */
	var $Conf;
	/**
	 * Module settings
	 */
	var $Settings;
	/**
	 * @var	int	Object ID of created module object
	 */
	var $ObjectID;

	/**
	 * @var	string	Language	Language of object
	 */
	var $ObjectLanguage;
	/**
	 * @var	int	Version	Version of object
	 */
	var $ObjectVersion;
	/**
	 * @var	string	ID string of object
	 */
	var $ObjectIDString;
	/**
	 * @var	int	ObjectLastEdited	Unix timestamp of last edited time
	 */
	var $ObjectLastEdited;
	/**
	 * @var string CurrentPage String with the Current Page, retrieved from the GET array.
	 */
	var $CurrentPage;

	/**
	 * Nitro default Module constructor
	 *
	 * This function initializes the DB, Session and configuration variables.
	 * Variables available in all child modules:
	 * * $this->DB, alias for $DB["Nitro"] (Nitro default DB handler)
	 * * $this->Sess, alias for $__NSess (Nitro default session object)
	 * * $this->Conf, alias for $__NitroConf->CONF (Nitro default configuration)
	 * 
	 * @access	private
	 */
	function NitroModule($Settings = FALSE)
	{
		global $DB, $__NSess, $__NitroConf;

		$this->CurrentPage = $_GET["P"];
		$this->DB = $DB["Nitro"];
		$this->Sess =& $__NSess; // Moet wel &, acc. to Siggi!
		$this->Conf = $__NitroConf->CONF;
		$this->ObjectLanguage = $this->Sess->Language;
		$this->ObjectVersion = 1;
		
		parent::NitroSettings();
		
		$this->SetSettings($this->GetSettingsFromDefinition($this->GetSettingsDefinition()));
	}

	/**
	 * Pre-Process the data for the module
	 *
	 * This function is called by Nitro on initialization of the object while
	 * gathering all objects for the page view. Normally this function would be
	 * empty, except for operations when the module should redirect the user to 
	 * a (new) page prior to doing any other processing. This should only be used
	 * for this in combination with saving posted ($_POST) data.
	 * 
	 * @access	public
	 */
	function PreProcess()
	{
		return TRUE;
	}

	/**
	 * Process the data for the module
	 *
	 * This function is called by Nitro prior to the call to one of the Draw
	 * functions. It is called on all modules before any Draw is called. This
	 * could be used when 2 modules on a page rely on the result of each other
	 * prior to drawing the modules.
	 * 
	 * @access	public
	 */
	function Process()
	{
		return TRUE;
	}

	/**
	 * Return the output of the module
	 *
	 * This function should return the output generated by the module. After this
	 * function is called, Nitro destroys the object.
	 * 
	 * @param 	array	$RuntimeSettings, module runtimesettings. Array of form Array("Param" => value ...)
	 * @access	public
	 * @return	string	Module output
	 */
	function Draw($RuntimeSettings = FALSE)
	{
		return FALSE;
	}

	/**
	 * Return the output stream of the module
	 *
	 * This function should return the object output generated by the module. This
	 * is only used in conjuntion with object data that needs to be streamed (Images,
	 * video, audio, flash etc.). After this function is called, Nitro destroys the
	 * object.
	 * 
	 * @param 	array	$RuntimeSettings, module runtimesettings. Array of form Array("Param" => value ...)
	 * @access	public
	 * @return	string	Module stream
	 */
	function DrawObject($RuntimeSettings = FALSE)
	{
		return $this->Draw($RuntimeSettings);
	}

	/**
	 * Return the output of the sections of the page
	 *
	 * This function should return the output of the module, similar to the Draw
	 * function, but now seperated into the sections defined by the module. This
	 * can be used in conjuntion with the GetXMLData (@see GetXMLData.php) function
	 * to refresh a certain part (section) of the page without a complete refresh.
	 * This function is also called by Nitro if the CreateSections option is set
	 * when an object is placed on a page. Nitro then automatically creates a "<DIV>"
	 * tag around the section with the ID given.
	 * <CODE>
	 * Array("Section1" => $string,
	 *       "Section1" => $strig2);
	 * After this function is called, Nitro destroys the object.
	 * </CODE>
	 *
	 * @param 	array	$RuntimeSettings, module runtimesettings. Array of form Array("Param" => value ...)
	 * @access	public
	 * @return	array	Module sections
	 */
	function DrawSections($RuntimeSettings = FALSE)
	{
		$tmp = $this->Draw($RuntimeSettings);
		if ($tmp) {
			return Array("Default" => $tmp);
		} else {
			return FALSE;
		}
	}

	/**
	 * Xml Call function outside page generation
	 *
	 * This function is used to call functions of modules directly in stead
	 * of drawing the whole page.
	 * This function should always be used in stead of calling the function
	 * $Function directly, because the real module and its function could be
	 * housed in a submodule and will only be available through this call!
	 *
	 * @param	string	$Function	Name of function to call
	 * @param	array		$Params		Parameters to pass to the function
	 */
	function XMLCall($Function, $Params = FALSE)
	{
		// Only allow Draw function as default
		if ($Function == 'Draw') {
			$rv = Array("Object" => $this->Draw());
		} else {
			$rv = FALSE;
		}

		return $rv;
	}

	/**
	 * Post-Process the data for the module
	 *
	 * This function is called by Nitro after the Draw function has been called.
	 * It could be used for setting extra information into the log or session after
	 * the module has finished all its processing etc.
	 * 
	 * @access	public
	 */
	function PostProcess()
	{
		return TRUE;
	}

	/**
	 * Return the module configuration options
	 *
	 * This function should return all configuration options the module will accept
	 * when creating a new (!) object in Nitro. Configuration options should be set
	 * according to the Nitro options string.
	 *
	 * @see Form
	 * @access	public
	 */
	function GetModuleConfiguration()
	{
		return FALSE;
	}

	/**
	 * Save the module configuration options
	 *
	 * Unlike the function suggests, this function does not save the object settings
	 * into the database, but prepares the settings to be saved by the object handler.
	 * Default, this function will just return the settings passed to it, without doing
	 * any processing.
	 *
	 * @param	Array	$SaveSettings	Settings filled in the object manager
	 * @access	public
	 */
	function SaveModuleConfiguration($SaveSettings)
	{
		return $SaveSettings;
	}

	/**
	 * Return the module data configuration options
	 *
	 * This function should return all configuration options the module will accept
	 * when creating a new (!) language/version dependant object in Nitro. Configuration
	 * options should be set according to the Nitro options string.
	 *
	 * @see Form
	 * @access	public
	 */
	function GetModuleDataConfiguration()
	{
		return FALSE;
	}

	/**
	 * Save the module data configuration options
	 *
	 * Unlike the function suggests, this function does not save the object settings
	 * into the database, but prepares the settings to be saved by the object handler.
	 * Default, this function will just return the settings passed to it, without doing
	 * any processing.
	 *
	 * @param	Array	$SaveSettings	Settings filled in the object manager
	 * @access	public
	 */
	function SaveModuleDataConfiguration($SaveSettings)
	{
		return $SaveSettings;
	}

	/**
	 * Set module settings
	 *
	 * This function sets the values of the module according to the values in de DB.
	 *
	 * @access	public
	 */
	function SetModuleSettings($Settings)
	{
		$this->SetSettings($Settings);
	}
	
	/**
	 * Get current module settings
	 *
	 * This function returns the current settings of the module.
	 *
	 * @access	public
	 */
	function GetModuleSettings()
	{
		return $this->Settings;
	}

	/**
	 * Return the module runtime-configuration options
	 *
	 * This function should return all runtime-configuration options the module will
	 * accept. This is given to the module when drawing the module and is meant to be
	 * used for drawing an object more than once on a certain page, without re-initializing
	 * the object.
	 * These settings are volatile and are not retained by the module after drawing.
	 *
	 * @access	public
	 */
	function GetModuleRuntimeConfiguration()
	{
		return FALSE;
	}

	/**
	 * Save the module runtime configuration options
	 *
	 * Unlike the function suggests, this function does not save the object settings
	 * into the database, but prepares the settings to be saved by the object handler.
	 * Default, this function will just return the settings passed to it, without doing
	 * any processing.
	 *
	 * @param	Array	$SaveSettings	Settings filled in the object manager
	 * @access	public
	 */
	function SaveModuleRuntimeConfiguration($SaveSettings)
	{
		return $SaveSettings;
	}

	/**
	 * The URL to use to retreive an object
	 *
	 * This function returns the URL use to retreive a raw object from
	 * the CMS.
	 *
	 * @param	string	$IDString	IDString of object
	 * @return	string	URL of object
	 * @access	public
	 */
	function GetObjectURL($IDString)
	{
		return "/GetObject.php?ID=".$IDString;
	}

	/**
	 * Is the module printable
	 *
	 * Return whether the module can be printed or not. Some modules, for instance
	 * business logic modules, do not produce output that can be printed. Default
	 * is not printable.
	 *
	 * @access	public
	 */
	function isPrintable()
	{
		return FALSE;
	}

	/**
	 * Is the module cacheable
	 *
	 * Returns a cache ID of the module output can be cached and false if the output
	 * of the module cannot be cached. Default is not cacheable.
	 *
	 * @access	public
	 */
	function isCacheable()
	{
		return FALSE;
	}

	/**
	 * Default cache ID for objects
	 *
	 * Returns a default cache ID of the module using the IDString, ObjectID, Object
	 * version, user language and last edited time.
	 *
	 * @access	public
	 */
	function cacheID()
	{
		return 'ID'.$this->IDString.'_OID'.$this->ObjectID.'_V'.$this->ObjectVersion.'_L'.NitroGetUserLanguage().'_LE'.$this->ObjectLastEdited.'_';
	}

	/**
	 * Return module install parameters
	 *
	 * This function should return all install paramters the module has. This includes
	 * language strings, templates, objects, pages and table definitions. These should
	 * be defined in this order.
	 * <CODE>
	 * // init an Array
	 * $Install = Array();
	 * 
	 * //Language strings needed
	 * $Install["Language"]["Title"]["nld"] = "Titel";
	 * $Install["Language"]["Date"]["nld"] = "Datum";
	 * $Install["Language"]["Body"]["nld"] = "Inhoud";
	 * $Install["Language"]["News Category"]["nld"] = "Nieuwscategorie";
	 * $Install["Language"]["Title"]["ice"] = "Titill";
	 * $Install["Language"]["Date"]["ice"] = "Dagsetning";
	 * $Install["Language"]["Body"]["ice"] = "Teksti";
	 * $Install["Language"]["News Category"]["ice"] = "Frétta kategorí";
	 * 
	 * // default templates to install
	 * // HTML template string
	 * $Install["Templates"]["NitroModuleNewsList"] = $ListTemplateHTML;
	 * // HTML template string
	 * $Install["Templates"]["NitroModuleNewsItem"] = $ItemTemplateHTML;
	 * // HTML template string
	 * $Install["Templates"]["NitroModuleNewsItemEdit"] = $ItemEditTemplateHTML;
	 * 
	 * // default objects to install
	 * $Install["Objects"]["NitroModuleNewsList"] =
	 *        Array(
	 *           "TemplateID" => GetNitroTemplateID("NitroModuleNewsList"),
	 *           "Edit" => 0, "NewsCategory" => NULL
	 *        );
	 * $Install["Objects"]["NitroModuleNewsEdit"] =
	 *        Array(
	 *           "TemplateID" => GetNitroTemplateID("NitroModuleNewsItemEdit"),
	 *           "Edit" => 1, "NewsCategory" => NULL
	 *        );
	 * $Install["Objects"]["NitroModuleNewsAdd"] =
	 *        Array(
	 *           "TemplateID" => GetNitroTemplateID("NitroModuleNewsItemEdit"),
	 *           "Edit" => 1,
	 *           "NewsCategory" => NULL
	 *        );
	 * 
	 * // default page to install
	 * $Install["Pages"]["NitroModuleNewsList"] =
	 *        Array(
	 *           "Language" => GetNitroDefaultLanguage(),
	 *           "Objects" => Array("Body" => GetNitroObjectID("NitroModuleNewsList")),
	 *           "TemplateID" => GetNitroDefaultTemplate(),
	 *           "Title" => "News",
	 *           "Published" => FALSE
	 *        );
	 * 
	 * // install news table
	 * $Install["Table"]["News"] = " ... table definition ... ";
	 * $Install["Table"]["NewsCategory"] = " ... table definition ... ";
	 * </CODE>
	 *
	 * @access	public
	 */
	function _InstallParameters()
	{
		return FALSE;
	}
	
	/**
	 * Return module upgrade parameters
	 *
	 * This function should return all parameter differences between the different
	 * versions of the module.
	 * Example:
	 *     TODO!!!
	 * 
	 * @access	public
	 * @todo		Create example for update parameters
	 */
	function _UpgradeParameters()
	{
		return FALSE;
	}
}
?>
Return current item: OpenNitro