Source for file ZNF.php
Documentation is available at ZNF.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* This source file is subject to version 2.1 of the GNU Lesser General Public
* License, that is bundled with this package in the file COPYING, available
* through the world wide web at the following URI:
* http://www.gnu.org/copyleft/lesser.html.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @author Tomasz Kuter <evolic@interia.pl>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
require_once('ZNF/Action/RequestProcessor.php');
require_once('ZNF/Config/AppConfig.php');
require_once('ZNF/Config/ModulesConfig.php');
require_once('ZNF/Presentation/Translation.php');
* <i>ZNF</i> provides the controller in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as Model 2.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @author Tomasz Kuter <evolic@interia.pl>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
* Version of the framework.
const VERSION = '0.7.10';
* Name of the GET attribute used to select the action to execute.
const ACTION_INDEX = 'znfAction';
* Name of the GET attribute used to select the module configuration.
const MODULE_INDEX = 'znfModule';
* Name of the GET attribute used to select persistently the module configuration.
const CHANGE_MODULE_INDEX = 'znfChangeModule';
* Name of the cache directory.
const CACHE_DIR = 'cache';
* Name of the config directory.
const CONFIG_DIR = 'config';
* Name of the language directory.
* Name of the libraries directory.
* Name of the modules directory.
const MODULES_DIR = 'modules';
* Name of the package templates directory.
const TEMPLATE_DIR = 'templates';
* Name of the package templates overlay directory.
const TEMPLATE_OVERLAY_DIR = 'packages';
* Name of the theme directory.
const THEME_DIR = 'themes';
* Debugging mode, set to true if you want to debug the application.
* ZNF credits, don't modify the line below.
const CREDITS = 'Powered by <a target="_blank" href="http://www.zeronotice.org">ZNF</a> » © 2004-2007 The ZNF Development Team » Released under the <a target="_blank" href="http://www.gnu.org/copyleft/lesser.html">GNU/LGPL</a> license';
* Constructs a new <i>ZNF</i> object.
* Processes the action requested with the correct <i>ZNF_Action_RequestProcessor</i>.
// get the app module config
$appModuleConfig = $appConfig->findModule($module);
// custom request processor selected
if ($appModuleConfig['processor']) {
$file = preg_replace('/_/', '/', $appModuleConfig['processor']) . '.php';
// selected custom request processor not found
// requires the file of the of the custom request processor
$processor = new $appModuleConfig['processor']($module);
$processor->preProcess($path);
$processor->process($path);
$processor->postProcess($path);
* Starts or reloads the session, setting the proper framework attributes for language, locale, theme and sessionId.
// get defaults from the configuration file
$sessionId = $appConfig->getSessionId();
// starts a new session if new session name is not equal previous
if ($sessionPrevId != $sessionId) {
// starts a new session if not set
if (!isset ($_SESSION['znf']['id'])) {
$lang = $appConfig->getLang();
$locale = $appConfig->getLocale();
$theme = $appConfig->getTheme();
if ($appConfig->getLangAutodetect() != 'false') {
// get language from the browser
if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$browserLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
if (file_exists(self::THEME_DIR . "/{$theme}/{$browserLang}")) {
// initializes session with framework attributes
$_SESSION['znf']['lang'] = $lang;
$_SESSION['znf']['locale'] = $locale;
$_SESSION['znf']['theme'] = $theme;
$_SESSION['znf']['authenticated'] = false;
$_SESSION['znf']['roles'] = array();
setlocale(LC_ALL, $_SESSION['znf']['locale']);
* Extracts the name of the action from the request.
* This method returns <i>null</i> if no action is found, then the
* <i>ZNF_Action_RequestProcessor->_processMapping()</i> select the default
* <i>action</i> element from the module configuration file.
return $_GET[ZNF::ACTION_INDEX];
* Extracts the name of the module from the request.
* This method returns <i>null</i> if no module is found, then the
* <i>ZNF_Config_ModulesConfig::getInstance()</i> returns the configuration
* of the default <i>module</i> element from the application configuration
$_SESSION['module'] = $_GET[ZNF::CHANGE_MODULE_INDEX];
return $_GET[ZNF::MODULE_INDEX];
if (isset ($_SESSION['module'])) {
return $_SESSION['module'];
* Update the name of the action in the request.
* This method is used by the <i>ZNF_Action_RequestProcessor</i> to forward
* the control flow to another module according to the current module
$_GET[ZNF::ACTION_INDEX] = $action;
* Update the name of the module in the request.
* This method is used by the <i>ZNF_Action_RequestProcessor</i> to forward
* the control flow to another module according to the current module
$_GET[ZNF::MODULE_INDEX ] = $module;
* <i>ZNFException</i> is the exception type for the <i>ZNF</i> class.
* <i>ZNFException</i> extends the <i>Exception</i> class of PHP5.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
|