File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/iwp.php
<?php
/**
* This file contains the IWP class. The main class that can set up a IWP page
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_API
*/
/**
* IWP Class
* This class is called to initialize every page. The main function is the Init() function where you can pass a list of things to load, or nothing to load everything.
*
* @package IWP
* @subpackage IWP_API
*/
class IWP {
/**
* This is a private variable that defaults to false and is set in the Init() function.
* If set to true it means all the init functions should be run. It is set to true if 'all' or not argument is passed into the Init function
*
* @var boolean
*
* @see Init()
*/
private static $loadAll = false;
/**
* This holds all the variables set in the whitelabel.php file.
*
* @var array
*
* @see InitWhiteLabel()
*/
public static $WhiteLabel = array();
/**
* This is a private variable that defaults to false and is set in the Init() function.
* If set to true it means all the essential init functions should be run. It is set to true if 'basic' is passed into the Init function.
* This would commonly be used if the code is being accessed by a third party script where it doesn't need everything that IWP does.
*
* @var boolean
*
* @see Init()
*/
private static $loadBasic = false;
/**
* This boolean values sets whether or not debug mode is on.
* When debug mode is on, information regarding the page load and number of queries is output using the output buffer callback function.
*
* @var boolean
*
* @see InitOutputBuffer()
*/
public static $DebugMode = false;
/**
* This boolean values sets whether or not demo mode is on.
* When demo mode is on:
* -> The system information page will not display critical information
* -> The settings page will not display database details
* -> The login form will have login information prefilled and display next to the fields
*
* @var boolean
*/
public static $DemoMode = false;
/**
* This boolean values sets whether or not mysql debug mode is on.
* When this is on, queries will be logged to files in the /tmp directory.
*
* @var boolean
*
* @see InitOutputBuffer()
*/
public static $DebugMySQLMode = false;
/**
* This is the folder name for the admin directory. It is not a full path, only a single directory name from the base IWP directory.
* If it is set to false or empty then the directory defaults to 'admin'
*
* @var string
*
* @see InitPaths()
*/
public static $AdminPath = 'admin';
/**
* This is the path to the modules directory from the base IWP directory. It defaults to /modules
*
* @var string
*
* @see InitPaths()
*/
public static $ModulesPath = '/modules';
/**
* This is the path to the cache directory from the base IWP directory. It defaults to /cache
*
* @var string
*
* @see InitPaths()
*/
public static $CachePath = '/cache';
/**
* This is the name of the language file to load from the language directory. It defaults to 'frontend'.
*
* @var string
*
* @see InitLanguage()
*/
public static $LangFile = 'frontend';
/**
* Set Variable Function
* This function sets a static variable within this class. It can only set variables that already exist.
*
* @param string $name The name of the variable to set
* @param string $value The value to set the variable to
*/
public static function Set($name, $value){
if(isset(self::$$name)){
self::$$name = $value;
}
}
/**
* Primary Initialization Function
* This function initializes different parts of the appliation based on the first argument
*
* @param string $load This specifies what to load. Can be 'all', 'basic' or a comma separated list of any of the following: session,autoload,error_reporting,paths,output_buffer,config,language,functions,whitelabel,timer,content_type_header,defines
* @param boolean $returnBase This specifies whether or not to return an instance of the iwp_base class.
*
* @return iwp_base Will return an instance of iwp_base if $returnBase is set to true
*/
public static function Init($load='all', $returnBase=false){
// turn off zend engine 1 compatibility mode
@ini_set('zend.ze1_compatibility_mode', 'off');
$options = array();
$availableOptions = array('session','autoload','errorreporting','paths','defines','outputbuffer','config','language','functions','whitelabel','timer','contenttypeheader');
$load = trim(strtolower(str_replace(array(' ','_'), '', $load)));
if($load !== 'all' && $load !== 'basic'){
self::$loadAll = false;
self::$loadBasic = false;
$dirtyOptions = explode(',', $load);
if(is_array($dirtyOptions)){
foreach($dirtyOptions as $val) {
if(in_array($val, $availableOptions,true)){
$options[] = $val;
}
if($val === 'basic'){
self::$loadBasic = true;
}
}
}
}else{
if($load === 'all'){
self::$loadAll = true;
}elseif($load === 'basic'){
self::$loadBasic = true;
}else{
self::$loadAll = false;
self::$loadBasic = false;
}
}
/**
* If we are on a windows system or this variable is defined, use it instead of
* REQUEST_URI
*/
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
/**
* Check for slashes in input!
*/
if (get_magic_quotes_gpc()) {
$_POST = self::stripslashes_deep($_POST);
$_GET = self::stripslashes_deep($_GET);
$_COOKIE = self::stripslashes_deep($_COOKIE);
$_REQUEST = self::stripslashes_deep($_REQUEST);
}
/**
* Fixes http://bugs.php.net/bug.php?id=42523
*/
if (isset($_SERVER['SERVER_SOFTWARE']) && (phpversion() == '5.2.4') &&
(is_numeric(strpos(strtolower($_SERVER['SERVER_SOFTWARE']),'iis')))) {
if (isset($_SERVER['SCRIPT_NAME'])) {
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
}
}
// The rest is loaded in particular order, as some are dependant on another (commonly, the paths)
if(self::$loadBasic || self::$loadAll || in_array('paths', $options)){
self::InitPaths();
}
if(self::$loadAll || in_array('outputbuffer', $options)){
self::InitOutputBuffer();
}
if(self::$loadAll || in_array('errorreporting', $options)){
self::InitErrorReporting();
}
if(self::$loadAll || in_array('timer', $options)){
self::InitTimer();
}
if(self::$loadBasic || self::$loadAll || in_array('autoload', $options)){
self::InitAutoload();
}
if(self::$loadBasic || self::$loadAll || in_array('config', $options)){
self::InitConfig();
}
if (self::$loadBasic || self::$loadAll || in_array('timezone', $options)) {
self::InitTimezone();
}
if (self::$loadBasic || self::$loadAll || in_array('events', $options)) {
self::InitEvents();
}
if(self::$loadAll || in_array('session', $options)){
self::InitSession(true);
}else{
self::InitSession(false);
}
if(self::$loadAll || in_array('language', $options)){
self::InitLanguage();
}
if(self::$loadBasic || self::$loadAll || in_array('functions', $options)){
self::InitFunctions();
}
if(self::$loadBasic || self::$loadAll || in_array('defines', $options)){
self::InitDefines();
}
if(self::$loadAll || in_array('whitelabel', $options)){
self::InitWhiteLabel();
}
if(self::$loadAll || in_array('contenttypeheader', $options)){
self::InitContentHeader();
}
if($returnBase){
return new iwp_base();
}
}
/**
* Recursive stripslashes
* This function string slashes for the request variables. This function is included in this class as the generic function library might not be loaded.
*
* @param mixed $value Can be an array or string. If its a string, stripslashes is run. If its an array, its children are passed back into the same array
*
* @return mixed The same as the input but with strip slashes run on them all.
*/
public static function stripslashes_deep($value)
{
if (is_array($value)) {
$value = array_map(array('IWP', 'stripslashes_deep'), $value);
} else {
$value = stripslashes($value);
}
return $value;
}
/**
* Initialize the functions library
* This function includes the general.php file which contains generic functions for use by IWP. It also includes the functions.*.php files in the same directory containing other generic functions.
*
* @return void
*/
private static function InitFunctions(){
require_once(IWP_BASE_PATH . '/lib/general.php');
}
/**
* Initialize the common constants
* This function includes the common.defines files which contains a lot of constants used throughout the application include the application version number
*
* @return void
*/
private static function InitDefines(){
// Loading the constants used within the application
require_once(IWP_BASE_PATH . '/lib/common.defines.php');
}
/**
* Initialize the event system
* This function initilises the event system.
*
* @return void
*/
public static function InitEvents ($force=false) {
if(IWP::isInstalled() || $force){
require_once(IWP_BASE_PATH . '/api/class.event.php');
iwp_event::init();
}
}
/**
* Initialize the php session
* This function initialises the session. If the config is loaded it will use the siteURL as the key, otherwise just the HTTP_HOST
*
* @return void
*/
private static function InitSession($init){
// Start the php session with a unique key
if(class_exists('iwp_config')){
$key = md5(iwp_config::Get('siteURL'));
}else{
$key = md5($_SERVER['HTTP_HOST']);
}
iwp_session::SetKey('IWP'. $key); // if the MD5 begins with a number it could result in an invalid root-level variable name
if($init){
if(isset($_POST['PHPSESSID']) && isset($_SERVER['HTTP_USER_AGENT']) && in_array(strtolower($_SERVER['HTTP_USER_AGENT']), array('shockwave flash', 'adobe flash player 10'), true)) {
iwp_session::Start($_POST['PHPSESSID']);
}else{
iwp_session::Start();
}
}
}
/**
* Initialize the autoload
* This function includes the autoload function file and also sets the autoload up using spl_autoload_register()
*
* @return void
*/
private static function InitAutoload(){
require_once(IWP_BASE_PATH . '/lib/autoload.php');
spl_autoload_register('iwp_autoload');
}
/**
* Initialize the error reporting
* This function sets up error reporting and sets some php.ini options: display_error, track_errors and magic_quotes_runtime
*
* @return void
*/
private static function InitErrorReporting(){
error_reporting(E_ALL);
@ini_set('display_errors', 1);
@ini_set('track_errors', '1');
@ini_set('magic_quotes_runtime', 'off');
}
/**
* Initialize the common application paths
* This function sets up the paths constants used throughout the application.
* The most widely uses and most important is IWP_BASE_PATH which is the path to the base IWP directory without a trailing slash.
* It also sets up the admin path, modules path and cache path
*
* @return void
*/
private static function InitPaths(){
define('IWP_BASE_PATH', dirname(dirname(__FILE__)));
if(!self::$AdminPath || self::$AdminPath == ''){
define('IWP_ADMIN_PATH', 'admin');
}else{
define('IWP_ADMIN_PATH', self::$AdminPath);
}
if(!self::$ModulesPath){
define('IWP_MODULES_PATH', IWP_BASE_PATH . '/modules');
}else{
define('IWP_MODULES_PATH', IWP_BASE_PATH . self::$ModulesPath);
}
if(!self::$CachePath){
define('IWP_CACHE_PATH', IWP_BASE_PATH . '/cache');
}else{
define('IWP_CACHE_PATH', IWP_BASE_PATH . self::$CachePath);
}
define('IWP_CACHE_SECTION_PATH', IWP_CACHE_PATH . '/sections');
define('IWP_CACHE_SECTION_HTML_PATH', IWP_CACHE_PATH . '/sectionhtml');
define('IWP_CACHE_TEMPLATE_PATH', IWP_CACHE_PATH . '/templates');
}
/**
* Initialize the Output Buffer Callback
* This function sets up the output buffer callback function. If debug mode was specified to be turned on then it will load the dubug.php function file. Otherwise just use the ob_gzhander() function.
*
* @return void
*/
private static function InitOutputBuffer(){
// Set up output buffering, the debug option should be set before the init
if(self::$DebugMode){
include_once(IWP_BASE_PATH . '/lib/debug.php');
ob_start('ob_callback_debug');
}else{
// Safari on mac has an issue with this in the control panel
$isSafari4OnMac = false;
if(isset($_SERVER['HTTP_USER_AGENT'])) {
$isSafari4OnMac = (preg_match('#Version/4\.0\.([0-9]*) Safari#i', $_SERVER['HTTP_USER_AGENT']) && preg_match('#mac os x#i', $_SERVER['HTTP_USER_AGENT']));
}
if (function_exists('ob_gzhandler') && !ini_get('zlib.output_compression') && @ini_get('output_handler') != 'ob_gzhandler' && !$isSafari4OnMac) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
}
}
/**
* Initialize the config file
* This function uses the config class to load the config file and set some constants regarding wether or not the application is installed or waiting for an upgrade.
*
* @return void
*/
private static function InitConfig(){
// Load the website configuration file, it has all the settings used by the application
iwp_config::Load();
// The following depend on the Config being loaded so this is why they are run in here
// If we're in the middle of an upgrade, we don't want certain things to run
if(iwp_config::Get('HideAdminUser') === false || iwp_config::Get('AdminEmail') === false){
define('WAITING_FOR_UPGRADE', true);
}else{
define('WAITING_FOR_UPGRADE', false);
}
// Set a constant to check if the application is installed or not
if(iwp_config::Get('isSetup') === false || iwp_config::Get('isSetup') == 0) {
define('NOT_INSTALLED', true);
} else {
define('NOT_INSTALLED', false);
}
// Check if the website title is being used or an alternative UseTextTitle
if(iwp_config::Get('UseTextTitle') && iwp_config::Get('UseAlternateTitle')){
iwp_config::Set('WebsiteTitle', iwp_config::Get('AlternateTitle'));
}else{
iwp_config::Set('WebsiteTitle', iwp_config::Get('siteName'));
}
// Set the template path
if(is_dir(IWP_BASE_PATH . "/templates/" . iwp_config::Get('template'))){
iwp_config::SetPublic('CurrentTemplateUrl', iwp_config::Get('siteURL') . "/templates/" . iwp_config::Get('template') );
iwp_config::SetPublic('CurrentTemplatePath', IWP_BASE_PATH . "/templates/" . iwp_config::Get('template') );
iwp_config::SetPublic('TemplateColor', iwp_config::Get('SiteColor'));
}else{
iwp_config::SetPublic('CurrentTemplateUrl', iwp_config::Get('siteURL') . "/templates/Default");
iwp_config::SetPublic('CurrentTemplatePath', IWP_BASE_PATH . "/templates/Default");
iwp_config::SetPublic('TemplateColor', 'blue');
}
}
/**
* Initialize the language pack
* This function loads the the language file dependant on the $LangFile member variable through the iwp_language class.
*
* @return void
*/
private static function InitLanguage(){
// Locale information
if (!defined('IWP_LOCALE_DEFAULT')) {
define('IWP_LOCALE_DEFAULT', 'en-US'); // note: this is only used for falling back to when no locale info is found in the config and should not be changed (should never happen, but this may prevent errors if it does)
}
// Is there a language file specified to use? If so, load it!
if(!self::$LangFile) {
$lang_file = 'frontend';
}else{
$lang_file = self::$LangFile;
}
if(strpos($lang_file, ',') !== false){
$lang_file = str_replace(' ', '', $lang_file);
$files = explode(',', $lang_file);
foreach($files as $file) {
iwp_language::getInstance()->Load($file, true);
}
}else{
iwp_language::getInstance()->Load($lang_file);
}
}
/**
* Initialize the WhiteLabel file
* This function includes the whitelabel file which contains constants and globals regarding whitelabeling of the product
*
* @return void
*/
private static function InitWhiteLabel(){
require_once(IWP_BASE_PATH . '/' . IWP_ADMIN_PATH . '/whitelabel.php');
if(is_array($whiteLabel)){
iwp_template::getInstance()->Assign('whitelabel', $whiteLabel, false);
self::$WhiteLabel = $whiteLabel;
}
}
/**
* Set the default timezone being used by the application
*
* @return void
*/
private static function InitTimezone () {
$tz = '';
if (class_exists('iwp_config')) {
$tz = iwp_config::Get('defaultTimezone');
}
if (!$tz) {
$tz = @date_default_timezone_get();
}
if ($tz) {
date_default_timezone_set($tz);
}
}
/**
* Initialize the application timer
* This function sets the start time for the script so it can be used to measure how long the script takes by subtracting this time from the finish time.
* Most commonly it is used in debug mode to output the script load time where the finish time is set inside the output bufferring callback.
*
* @return void
*/
private static function InitTimer(){
list($usec, $sec) = explode(' ', microtime());
$GLOBALS['start_time'] = ((float)$usec + (float)$sec);
}
/**
* Initialize the content type header
* This function outputs a text/html content header if the request is not for remote.php or for a file download.
*
* @return void
*/
private static function InitContentHeader(){
// Set up character-set header information
if(class_exists('iwp_config')){
$charset = iwp_config::Get('charset');
}else{
$charset = 'utf-8';
}
if(isset($_SERVER['REQUEST_URI'])) {
if(!strstr($_SERVER['REQUEST_URI'],"download") && !strstr($_SERVER['REQUEST_URI'],"remote.php")){
header("Content-Type: text/html; charset=".$charset);
}
}
}
/**
* Loads a PHP class file from the 'lib' directory
*
* @param string $lib_file
*/
public static function GetLib($lib_file){
$FullFile = IWP_BASE_PATH . '/lib/'.$lib_file.'.php';
if(is_file($FullFile)){
include_once($FullFile);
}
}
public static function isInstalled(){
return iwp_config::Get('isSetup');
}
public static function SetupDatabaseTableNames(){
if(!self::isInstalled()){
return;
}
define("TABLE_PREFIX", iwp_config::Get('tablePrefix'));
define("IWP_TABLE_CATEGORIES", iwp_config::Get('tablePrefix') . "categories");
define("IWP_TABLE_CATASSOC", iwp_config::Get('tablePrefix') . "categoryassociations");
define("IWP_TABLE_GROUPASSOC", iwp_config::Get('tablePrefix') . "groupassociations");
define("IWP_TABLE_GROUPPERMS", iwp_config::Get('tablePrefix') . "grouppermissions");
define("IWP_TABLE_GROUPS", iwp_config::Get('tablePrefix') . "groups");
define("IWP_TABLE_USERS", iwp_config::Get('tablePrefix') . "users");
define("IWP_TABLE_SETTINGS", iwp_config::Get('tablePrefix') . "settings");
define("IWP_TABLE_CONTENT", iwp_config::Get('tablePrefix') . "content");
define("IWP_TABLE_VIEWS", iwp_config::Get('tablePrefix') . "views");
define("IWP_TABLE_CONTENTTYPES",iwp_config::Get('tablePrefix') . "content_types");
define("IWP_TABLE_CONTENTVARS",iwp_config::Get('tablePrefix') . "content_vars");
define("IWP_TABLE_MODULES", iwp_config::Get('tablePrefix') . "modules");
define("IWP_TABLE_LIST_FILTERS",iwp_config::Get('tablePrefix') . "list_filters");
define("IWP_TABLE_LIST_LINKS", iwp_config::Get('tablePrefix') . "list_links");
define("IWP_TABLE_LISTS", iwp_config::Get('tablePrefix') . "lists");
define("IWP_TABLE_LIST_SORTCACHE", iwp_config::Get('tablePrefix') . "list_sortcache");
define("IWP_TABLE_TEMPLATE_SETTINGS", iwp_config::Get('tablePrefix') . "template_settings");
define("IWP_TABLE_TEMPLATE_DATA", iwp_config::Get('tablePrefix') . "template_data");
define("IWP_TABLE_URLS", iwp_config::Get('tablePrefix') . "urls");
define("IWP_TABLE_CONTENTSEARCH", iwp_config::Get('tablePrefix') . "content_views");
define("IWP_TABLE_IMPORT", iwp_config::Get('tablePrefix') . "import");
// define the prefix for module tables
define("IWP_MODULE_DB_PREFIX", iwp_config::Get('tablePrefix') . "module_");
}
}