Sources for file plugins/class/options.php in version 4.0 Beta 1



Click on a comment to hide it. Click here to show all comments.

/**
 * Project:     Xnyo 4: Bubbles
 * File:        plugins/class/options.php
 *
 * Version:     
 * SVN Id:      $Id: options.php 5 2007-05-18 03:49:07Z bok $
 * SVN URL:     $HeadURL:
http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/class/options.php $
 * Authors:     Robert Amos <bok[at]odynia.org>
 *
 * Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/

/**
 * So we don't include this fail again.
**/
define('XNYO_OPTIONS_LOADED'true);

/**
 * XnyoOptions
 *
 * Sets the default properties for the $xnyo->options object.
**/
class XnyoOptions extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Options',
        
'description' => 'Sets the default properties used for $xnyo->whatever',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'options',
        
    );
    
    function 
__construct()
    {
        
/**
         * Destructor
         *
         * Xnyo allows for a function to be called at the destruction of the page,
         * that is to say, the end of the PHP script, before it runs its own
         * destruction routines.
        **/
        
$this->destructor NULL;
        
        
/**
         * Trim Whitespaces
         *
         * Xnyo has the option to trim unnecessary whitespaces on output, cutting back
         * on the amount of data it has to send to the client. Set this to true
         * to enable it.
        **/
        
$this->trim false;
        
        
/**
         * Xnyo Version
        **/
        
$this->version '4.0-dev';

        
// call parent constructor
        
parent::__construct();
    }
}


/**
 * Supported Xnyo Database Types
**/
define('XNYO_DATABASE_PGSQL''XnyoDatabasePostgreSQL');
define('XNYO_DATABASE_MYSQL''XnyoDatabaseMySQL');
//define('XNYO_DATABASE_SQLITE', 'XnyoDatabaseSQLITE');
//define('XNYO_DATABASE_ORACLE', 'XnyoDatabaseOracle');
//define('XNYO_DATABASE_MSQL', 'XnyoDatabaseMSQL');


/**
 * Supported Xnyo Authentication Types
**/
define('XNYO_AUTH_SQL''XnyoAuthSQL');
define('XNYO_AUTH_ACTIVEDIRECTORY''XnyoAuthActiveDirectory');


/**
 * XnyoOptionsSession Class
 * 
 * This class sets the default properties for the $xnyo->session object.
**/
class XnyoOptionsSession extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Session Options',
        
'description' => 'Sets the default properties for $xnyo->session->whatever',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'session',
        
    );
    
    public function 
__construct ()
    {
        
/**
         * Xnyo's built-in session/authentication controls allow for the management
         * of any visitors.
         *
         *
         * Authentication Module
         *
         * This is the module that Xnyo will use to connect to the Authentication Source.
         * This should be set to one of the XNYO_AUTH_* constants, or to a string containing the
         * class that should be used. This needs to be a class that has implemented
         * the XnyoAuthPlugin interface. It should reside in your auth plugin directory.
        **/
        
$this->handler XNYO_AUTH_SQL;

        
/**
         * Session Lifetime
         *
         * This is how long a logged in session may be idle for before being removed
         * from the active session list. The default of 1 day is suitable for most
         * websites, web applications or applications with sensitive data might want to
         * lower this. Please note that by default Xnyo sessions do not persist after
         * someone has closed their browser.
        **/
        
$this->lifetime 86400;

        
/**
         * Authentication Parameters
         *
         * This array should contain extra information to be passed to the authentication module.
         * Please see the plugins in the plugin/auth/ directory for more information.
        **/
        
$this->params = array();

        
/**
         * Logout Handler
         *
         * After Xnyo has logged a user out of the system, it will create an instance of the class
         * specified below. This should be a class that implements XnyoLogoutInterface.
        **/
        
$this->logout_handler NULL;

        
/**
         * Set Language
         *
         * Xnyo has the ability to determine what language the user's browser is set for.
         * This allows you to build up multi-user sites. Xnyo does not control how you do this
         * but will merely set the $xnyo->language variable to the language supported by the brower.
         * Use this to shape your site as your please. This is the default behaviour. Define XNYO_LANGUAGE
         * to false if you would like to turn this behaviour off. Also, the session's language
         * can be overridden by passing through a lang=whatever GET/POST/COOKIE variable.
         *
         * The "languages" variable below should contain an array of "shortname" => "longname" pairs.
         * The default includes only English.
        **/
        
$this->languages = array
        (
            
'en' => 'English',
        );

        
/**
         * Default Language
         *
         * This is what language the session defaults to, should one not be set.
        **/
        
$this->default_language 'en';
        
        
/**
         * Errors
         *
         * Change these to change the error message that is returned to the client
        **/
        
$this->errors = array
        (
            
'blank_username' => 'Blank username specified. Please enter your username.',
            
'blank_password' => 'Blank password specified. Please enter your password.',

            
// %d will be the number of seconds that the session has expired by
            
'session_timeout' => 'Session expired by <b>%d seconds</b>. You will be logged out.',
            
            
// the first %s will be the original subnet mask, second %s will be the new non-matching one
            
'subnet_change' => 'Session has moved subnet from <b>%s</b> to <b>%s</b>. You will be logged out
for security reasons.'
,

            
// the first %s will be the original browser, second %s will be the new non-matching one
            
'browser_change' => 'Session has changed browsers from <b>%s</b> to <b>%s</b>. You will be logged
out for security reasons.'
,

            
// access denied
            
'access_denied' => 'Access is Denied. Please check your username and password, and try again.',
            
            
// invalid password
            
'invalid_login' => 'Invalid login credentials, please check your username and password and try
again.'
        
);

        
// call parent constructor
        
parent::__construct();
    }
}

/**
 * Supported Error Handlers
**/
define('XNYO_ERROR_XNYO''XnyoErrorXnyo');

/**
 * XnyoOptionsError Class
 *
 * This class sets the default properties for the $xnyo->error object.
**/
class XnyoOptionsError extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Error Options',
        
'description' => 'This sets the default properties for the $xnyo->error->whatever',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'error'
    
);

    
// Constructor
    
public function __construct ()
    {
        
/**
         * Error Handler
         *
         * This sets the module that Xnyo will attempt to use in error handling. This should
         * be set to one of the XNYO_ERROR_* constants, or a string containing the
         * class that should be used. This needs to be a class that has implemented
         * the XnyoErrorPlugin interface. It should reside in your error plugin directory.
        **/
        
$this->handler XNYO_ERROR_XNYO;
    }
    
    
/**
     * Whether to Log Notices / Strict
    **/
    
public $logmisc true;
    

}
/**
 * Supported Cache Handlers
**/
define('XNYO_CACHE_FILE''XnyoCacheFile');
define('XNYO_CACHE_DATABASE''XnyoCacheDatabase');

/**
 * XnyoOptionsCache Class
 * 
 * This class sets the default properties for the $xnyo->cache object.
**/
class XnyoOptionsCache extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Cache Options',
        
'description' => 'This sets the default properties for $xnyo->cache->whatever',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'cache',
    );

    public function 
__construct ()
    {
        
/**
         * Cache Handler
         *
         * This sets the module that Xnyo will attempt to use in caching. This should be set
         * to one of the XNYO_CACHE_* constants, or to a string containing the
         * class that should be used. This needs to be a class that has implemented
         * the XnyoCachePlugin interface. It should reside in your cache plugin directory.
        **/
        
$this->handler XNYO_CACHE_FILE;

        
/**
         * Cache Lifetime.
         *
         * How long a cached page/bubble should remain cached before its regenerated.
         * This should be overridden on a page-by-page basis. Note that if you set the
         * cache expiration time below or idle time, that will override this setting. This can also
         * be overriden by the cache table.
        **/
        
$this->lifetime 86400;

        
/**
         * Cache Idle Time
         * 
         * This is the time that a page should remain un-accessed before it is regenerated.
         * For example, if you set a page to an hour's idle time, if no one views that page
         * for an hour, it is regenerated.
        **/
        
$this->idletime NULL;

        
/**
         * Cache Expiration Time
         *
         * Sets a definite time (expressed as a unix timestamp relative to the server time)
         * that the cache should expire. 
        **/
        
$this->expiration NULL;

        
/**
         * Cache Location
         *
         * Location that the cache should be kept in. For the file handler its a directory,
         * for the database one it is a table in the dbspec.
        **/
        
$this->location 'cache';

        
/**
         * Cache ID
         *
         * Used for things like bubbles. If you would like the to store something in the 
         * cache that is independant of the current page. Like a snippet etc. Set this ID and
         * it will be used instead of the current page.
        **/
        
$this->id NULL;

        
// call parent constructor
        
parent::__construct();
    }
}

/**
 * Variable Filter
 *
 * The Xnyo variable filter automatically empties the $_GET, $_SET, $_COOKIES,
 * $_REQUEST and $_SERVER superglobals. You then need to populate them again using the
 * $xnyo->filter_<type>() functions, at which time they are filtered. THIS IS FOR
 * SECURITY AND SHOULD NOT BE DISABLED, ESPECIALLY NOT FOR LAZINESS. You can turn off
 * the filter through the use of the XNYO_FILTER constant. Again don't turn it off
 * unless you have a really really good reason.
**/
class XnyoOptionsFilter extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Filter Options',
        
'description' => 'This sets the default properties for $xnyo->filter->whatever',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'filter'
    
);

    public function 
__construct ()
    {
        
/**
         * Global Vars
         *
         * This works the same as PHP's register_globals ini option. It copies variables
         * to the global scope as they're filtered. Still not recommended for security reasons.
        **/
        
$this->globals false;

        
/**
         * Modified Arrays
         * 
         * These arrays are a mirror of their respective superglobals. If a variable is modified
         * during filtering, a corresponding element is added here.
         * So if you run $xnyo->filter_get('moo', 'int'); you get $_GET['moo'] and
         * $xnyo->filter->get['moo'] will be set to a boolean to indicate if the variable
         * was modified during filtering.
        **/
        
$this->get = array();
        
$this->post = array();
        
$this->cookie = array();
        
$this->server = array();
        
$this->request = array();        
        
$this->env = array();

        
// call parent constructor
        
parent::__construct();
    }
}

/**
 * Smarty
 *
 * Although Smarty is known as a "Template Engine", it would be more accurately described as a
 * "Template/Presentation Framework." That is, it provides the programmer and template designer
 * with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an
 * application. I stress the word Framework because Smarty is not a simple tag-replacing template
 * engine. Although it can be used for such a simple purpose, its focus is on quick and painless
 * development and deployment of your application, while maintaining high-performance, scalability,
 * security and future growth.
 *
 * See http://smarty.php.net/rightforme.php
**/
class XnyoOptionsSmartyVar extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Smarty Variable Options',
        
'description' => 'This sets the default properties for $xnyo->smartyvar->whatever. Contents of
this object are automatically available in {$xnyo.}'
,
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'smartyvar'
    
);
    
    
// Constructor
    
public function __construct ()
    {
        
parent::__construct();
    }
    
    
/**
     * Initialize the {$xnyo} variable
    **/
    
public function init ($obj=null)
    {
        if (
is_object($obj))
            
$smarty $obj;
        elseif (isset(
$GLOBALS['smarty']) && is_object($GLOBALS['smarty']))
            
$smarty $GLOBALS['smarty'];
        else
            return 
false;
        if (
XNYO_DEBUG$this->xnyo->d('Initialising Smarty {$xnyo} magic variable.');
        
$smarty->assign_by_ref('xnyo'$this->options);
    }
}

/**
 * Debug Console
 *
 * Xnyo includes a Debug Console that lets you know exactly what happens during the life of a
Xnyo-enhanced
 * request. See the example at http://xnyo.odynia.org/?xnyo_debug=true
**/
class XnyoOptionsDebug extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Debug Options',
        
'description' => 'This sets the default properties for $xnyo->debug->whatever.',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'debug',
        
    );

    public function 
__construct ()
    {
        
/**
         * Debug Template
         *
         * This is the Smarty template that Xnyo uses to display the debug console.
        **/
        
$this->template XNYO_DIR.'plugins'.DIRSEP.'error'.DIRSEP.'debug.tpl';
        
        
/**
         * Allow Debug
         *
         * ! This option is now set using the Constant XNYO_DEBUG_ALLOW before loading Xnyo. !
         *
         * This sets whether or not Xnyo is allowed to look for the variable as defined by XNYO_DEBUG_VAR
         * in the $_REQUEST variables. If Xnyo finds this variable it will enable debug accordingly.
         * This enables you to selectively turn on debugging by appending (eg) ?xnyo_debug=true to a page.
        **/
        //$this->allow = false;
        
        /**
         * Debug Variable
         *
         * ! This option is now set using the Constant XNYO_DEBUG_VAR before loading Xnyo. !
         * 
         * If XNYO_DEBUG_ALLOW is true, Xnyo will check the GET/POST/COOKIE variables for the
         * variable name listed here. If it finds it it will enable debugging for that request only.
        **/
        //$this->varname = 'xnyo_debug';
        
        /**
         * Debug Log
         *
         * ! This option is now set using the Constant XNYO_DEBUG_LOG before loading Xnyo. !
         *
         * If this variable is set to true, Xnyo will include its debug messages in with the PHP ones.
         * This assumes that you already have your server configured to log PHP error messages.
        **/
        //$this->log = false;

        // call parent constructor
        
parent::__construct();
    }
}

// Plugin Types
if (!defined('XNYO_PLUGIN_AUTH')) define('XNYO_PLUGIN_AUTH''auth');
if (!
defined('XNYO_PLUGIN_BUBBLE')) define('XNYO_PLUGIN_BUBBLE''bubble');
if (!
defined('XNYO_PLUGIN_CACHE')) define('XNYO_PLUGIN_CACHE''cache');
if (!
defined('XNYO_PLUGIN_CLASS')) define('XNYO_PLUGIN_CLASS''class');
if (!
defined('XNYO_PLUGIN_DATABASE')) define('XNYO_PLUGIN_DATABASE''database');
if (!
defined('XNYO_PLUGIN_DBSPEC')) define('XNYO_PLUGIN_DBSPEC''dbspec');
if (!
defined('XNYO_PLUGIN_ERROR')) define('XNYO_PLUGIN_ERROR''error');
if (!
defined('XNYO_PLUGIN_SMARTY')) define('XNYO_PLUGIN_SMARTY''smarty');


// Plugin Actions
if (!defined('XNYO_PLUGIN_ACTION_GLOBAL')) define('XNYO_PLUGIN_ACTION_GLOBAL'1);
if (!
defined('XNYO_PLUGIN_ACTION_STORAGE')) define('XNYO_PLUGIN_ACTION_STORAGE'2);
if (!
defined('XNYO_PLUGIN_ACTION_RETURN')) define('XNYO_PLUGIN_ACTION_RETURN'3);
if (!
defined('XNYO_PLUGIN_ACTION_NONE')) define('XNYO_PLUGIN_ACTION_NONE'4);


/**
 * Plugins
 * 
 * This class sets the default properties for the $xnyo->plugins object.
**/
class XnyoOptionsPlugins extends XnyoOptionsBase
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Plugin Options',
        
'description' => 'This sets the default properties for $xnyo->plugins->whatever.',
        
'action' => XNYO_PLUGIN_ACTION_NONE,
        
'varname' => 'plugins',
    );

    public function 
__construct ()
    {
        
/**
         * Plugin Directories
         *
         * This is where Xnyo will look for plugins.  List here directories that you
         * would like Xnyo to search for plugins. These can be absolute paths or paths relative to the
         * SCRIPT_DIR or XNYO_DIR. It will prepend the directories in that order, so that user
         * plugins by the same name in the SCRIPT_DIR will be used instead of the included ones in
XNYO_DIR.
        **/
        
$this->dirs = array
        (
            
'plugins'
        
);
        
        
/**
         * Plugin Extension
         *
         * The extension that plugins have, usually .php
        **/
        
$this->ext '.php';
        
        
/**
         * Bubbles
         *
         * If this is set to true and Xnyo is currently processing a bubble, it will check the bubble
         * directory for a "plugins" directory. If it finds one it will use the bubble's plugins before
         * the regularly configured plugins, should one be available.
        **/
        
$this->bubbles true;

        
// call parent constructor
        
parent::__construct();
    }

    
/**
     * Overwrite the __set handler
    **/
    
public function __set ($var$value)
    {
        
// call the original one
        
parent::__set($var$value);

        
// are we changing the plugin directory structure? after the constructor has finished of course..
        
if ($var == 'dirs' && !$this->silent)
            
$this->update_smarty_dir();
    }
    
    
/**
     * Update Smarty Directories
    **/
    
public function update_smarty_dir ($obj=null)
    {
        
// not registered yet?
        
if (is_object($obj))
            
$s $obj;
        elseif (isset(
$GLOBALS['smarty']) && is_object($GLOBALS['smarty']))
            
$s $GLOBALS['smarty'];
        else
            return 
false;

        
// iterate over the new directories
        
$sdirs = array();
        foreach (
$this->dirs as $dir)
        {
            
// append smarty to the directory
            
$dir rtrim($dirDIRSEP).DIRSEP.'smarty';
            
$sdirs[] = $dir;

            
// if its not an absolute path..
            
if ($dir{0} != DIRSEP)
            {
                if (
defined('ROOT_DIR')) $sdirs[] = ROOT_DIR.$dir;
                
$sdirs[] = XNYO_DIR.$dir;
            }
        }

        
// update the smarty object
        
if (XNYO_DEBUG$this->xnyo->d('Updating Smarty plugin directory list.');
        
$s->plugins_dir $sdirs;
    }
}

/**
 * XnyoOptionsBase
 *
 * This class implements the magic variables that monitor the settings.
**/
class XnyoOptionsBase
{
    
/**
     * Storage
    **/
    
protected $options = array();
    protected 
$silent true;
    protected 
$xnyo;
    
    
/**
     * Constructor
    **/
    
public function __construct ()
    {
        
$this->xnyo $GLOBALS['xnyo_parent'];

        
// allow debugging messages through after the constructors have
        // run, this keeps it from spamming the debug log with default
        // values
        
$this->silent false;
    }

    
/**
     * Get content of option
    **/
    
public function __get ($var)
    {
        if (!isset(
$this->options[$var]))
            return 
null;
        return 
$this->options[$var];
    }
    
    
/**
     * Set option
    **/
    
public function __set ($var$value)
    {
        if (
XNYO_DEBUG && !$this->silent$this->xnyo->d('Setting value of <b>%s::%s</b> to <b>%s</b>.',
get_class($this), $var$value);
        
$this->options[$var] = $value;
    }
    
    
/**
     * Isset
    **/
    
public function __isset ($var)
    {
        return isset(
$this->options[$var]);
    }
}

Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.