<?php /* _\|/_ vim: set et ts=4 sw=4 sts=4 nowrap fdm=marker:
(o o)
+-----oOO-{_}-OOo--------------------------------------------------------+
| ConPresso - Foolproof Content Management |
+------------------------------------------------------------------------+
| Copyright (c) Bartels Schoene GmbH & Co. KG, 48149 Muenster, Germany |
+------------------------------------------------------------------------+
| This source file is subject to ConPresso license version 2002-11-16 |
| that is bundled with this package in the files LICENSE_EN.TXT or |
| LICENSE_DE.TXT, and is available through the world-wide-web at |
| http://www.conpresso.de/license/LICENSE_EN-2002-11-16.TXT or |
| http://www.conpresso.de/license/LICENSE_DE-2002-11-16.TXT |
| |
| If you did not receive a copy of the ConPresso license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| <license@conpresso.de> so we can e-mail you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: ConPresso development and support team <support@conpresso.de> |
+------------------------------------------------------------------------+
$Id: common.inc.php 170 2007-03-09 20:30:22Z balu $ */
if (!defined('CPO')) exit;
// set some PHP defaults that break CPOs behaviour
@ini_set('error_reporting', 2039);
@ini_set('magic_quotes_runtime', false);
@ini_set('magic_quotes_sybase', false);
define('CPO_BASEDIR', realpath(dirname(__FILE__).'/../').'/');
// make sure that $directory can not be set externally
$directory = basename(dirname($_SERVER['PHP_SELF']));
// load common functions
require_once(CPO_BASEDIR.'_include/constants.inc.php');
require_once(CPO_BASEDIR.'_include/function.php');
require_once(CPO_BASEDIR.'_include/printnavigation.inc.php');
// FIXME This should be done as a workaround only until the transition to superglobals got finished
// Note: this only imports GET, POST and COOKIE variables, not SERVER, FILES, ENV, or SESSION!
@import_request_variables('cgp'); // CGP to avoid problems with cookies from other pages
// strip magic quotes from Superglobals...
if ((bool) get_magic_quotes_GPC()) { // by "php Pest"
// Really EGPCSR - Environment $_ENV, GET $_GET , POST $_POST, Cookie $_COOKIE, Server $_SERVER
// and their HTTP_*_VARS cousins (separate arrays, not references) and $_REQUEST
$fnStripMagicQuotes = create_function(
'&$mData, $fnSelf',
'if (is_array($mData)) { foreach ($mData as $mKey=>$mValue) $fnSelf($mData[$mKey], $fnSelf); return; } '.
'$mData = stripslashes($mData);'
);
$fnStripMagicQuotes($_POST, $fnStripMagicQuotes); // do each set of EGPCSR as you find necessary
$fnStripMagicQuotes($_GET, $fnStripMagicQuotes);
$fnStripMagicQuotes($_REQUEST, $fnStripMagicQuotes);
}
// some variables
$CPO['skin'] = 'conpresso';
$CPO['version'] = '4.0.7';
// initialize debugging variables
$CPODEBUG = 0;
$CPODEBUGLOG = array();
$CPODEBUGQUERYCOUNT = 0;
list($usec, $sec) = explode(' ', microtime());
$CPODEBUGRUNNINGSTART = (float)$usec + (float)$sec;
// old mechanism
$varDEBUG = 0; // 0 = kein DEBUG, 1 = std. DEBUG , 4 = alle DEBUG
$tagsPreg = '/<!--\s*(file|html|image|text|url|value)\s*:\s*([^;]*?)\s*(;\s*(.*?)\s*)?-->/si'; // FIXME replace this with the stuff in $hdl_parser_*
$typeNames = array('', 'file', 'html', 'image', 'text', 'url', 'value');
$NextSpan = 2; // show $NextSpan neighbour pages
$NextSpan10 = true; // show every 10th page
$NextSpanSpace = ' ... '; // placeholder for not shown pages
$notimeout = false;
if (!isset($pagetype)) $pagetype = 'index';
// standard-handler
$hdlr_navigation = array('include: '.urlencode('_include/basic_navigation.inc.php'));
$hdlr_parser_content['file'] = array('include: '.urlencode('_include/parser_c_file.inc.php'));
$hdlr_parser_content['html'] = array('include: '.urlencode('_include/parser_c_html.inc.php'));
$hdlr_parser_content['image'] = array('include: '.urlencode('_include/parser_c_image.inc.php'));
$hdlr_parser_content['text'] = array('include: '.urlencode('_include/parser_c_text.inc.php'));
$hdlr_parser_content['url'] = array('include: '.urlencode('_include/parser_c_url.inc.php'));
$hdlr_parser_content['value'] = array('include: '.urlencode('_include/parser_c_value.inc.php'));
$hdlr_parser_replacement['file'] = array('include: '.urlencode('_include/parser_r_file.inc.php'));
$hdlr_parser_replacement['html'] = array('include: '.urlencode('_include/parser_r_html.inc.php'));
$hdlr_parser_replacement['image'] = array('include: '.urlencode('_include/parser_r_image.inc.php'));
$hdlr_parser_replacement['text'] = array('include: '.urlencode('_include/parser_r_text.inc.php'));
$hdlr_parser_replacement['url'] = array('include: '.urlencode('_include/parser_r_url.inc.php'));
$hdlr_parser_replacement['value'] = array('include: '.urlencode('_include/parser_r_value.inc.php'));
$cpoRubricDefaults = array(
'directory' => '_rubric',
'name' => '',
'seclevel' => SECLEVEL_PUBLIC
);
// setup system settings
$cpoSystemDefaults = array(
'owner' => '',
'lkey' => '',
'project' => 'ConPresso 4',
'release' => false,
'system_email' => '', // FIXME I don't like these defaults
'admin_email' => '',
'timeout' => 3*60*60,
'max_image' => 2*1024*1024,
'max_file' => 2*1024*1024,
'language' => 'english',
'base_url' => '',
'targets' => '_self _blank _top',
'send_pw' => true,
'help' => true,
'noOfFiles' => 5,
'noOfArticles' => 10,
'noOfUploadFiles' => 5,
'homepage' => '_admin/index.php',
'statistics' => false,
'sessionsInDB' => true,
'ipcheck' => false,
'startnews' => true,
'date_format' => 'Y-m-d H:i',
'editorCSS' => '',
'CSSURL' => '',
'installed' => time(), // actual date as default installation time
'PATH_INFO' => false,
'logfiledays' => 365,
'nolocktables' => false
);
$cpoSystem = $cpoSystemDefaults;
// don't initialize database settings, etc during setup
if (!defined('SETUP')) {
require_once(CPO_BASEDIR.'_include/db_mysql.inc.php');
if (!is_readable(CPO_BASEDIR.'_cfg/db.inc.php'))
die('ConPresso is not configured yet! Please run the setup or make sure '.CPO_BASEDIR.'_cfg/db.inc.php is readable.');
require_once(CPO_BASEDIR.'_cfg/db.inc.php');
define('CPO_BLOCK', $dbPrefix.'_block');
define('CPO_CONTENT_FILES', $dbPrefix.'_content_files');
define('CPO_CONTENT_HTML', $dbPrefix.'_content_html');
define('CPO_CONTENT_IMAGES', $dbPrefix.'_content_images');
define('CPO_CONTENT_TEXT', $dbPrefix.'_content_text');
define('CPO_CONTENT_URLS', $dbPrefix.'_content_urls');
define('CPO_DATA', $dbPrefix.'_data');
define('CPO_LOG', $dbPrefix.'_log');
define('CPO_LOG_LOGIN', $dbPrefix.'_log_login');
define('CPO_MODULES', $dbPrefix.'_modules');
define('CPO_NAVTREE', $dbPrefix.'_navtree');
define('CPO_NEWS', $dbPrefix.'_news');
define('CPO_OPTION', $dbPrefix.'_option');
define('CPO_PERMISSION', $dbPrefix.'_permission');
define('CPO_PLACEHOLDERS', $dbPrefix.'_placeholders');
define('CPO_RUBRIC', $dbPrefix.'_rubric');
define('CPO_RUBRIC_PERMISSION', $dbPrefix.'_rubric_permission');
define('CPO_SESSIONS', $dbPrefix.'_sessions');
define('CPO_SNIPPET', $dbPrefix.'_snippet');
define('CPO_STATISTICS', $dbPrefix.'_statistics');
define('CPO_TEMPLATES', $dbPrefix.'_templates');
define('CPO_TPL_ASSIGNMENT', $dbPrefix.'_tpl_assignment');
define('CPO_USER', $dbPrefix.'_user');
define('CPO_USERGROUPS', $dbPrefix.'_usergroups');
// overwrite default settings with the ones from the database
$db = new DB;
$db->query('SELECT options FROM '.CPO_OPTION.' '
."WHERE type='system'");
while ($db->next_record()) {
$options = $db->v('options');
$t_cpoSystem = unserialize($options);
if (!is_array($t_cpoSystem)) break;
foreach ($t_cpoSystem as $key=>$v) {
$cpoSystem[$key] = $v;
}
}
// start session (use database handler?)
CPOsession_start();
}
// always use sensible defaults
if ($cpoSystem['timeout']<5*60) $cpoSystem['timeout'] = 5*60;
if ($cpoSystem['noOfFiles']<1) $cpoSystem['noOfFiles'] = 1;
if ($cpoSystem['noOfArticles']<1) $cpoSystem['noOfArticles'] = 1;
if ($cpoSystem['noOfUploadFiles']<1) $cpoSystem['noOfUploadFiles'] = 1;
if ($cpoSystem['language']=='') $cpoSystem['language'] = 'english';
// language files
require_once(CPO_BASEDIR.'_include/translation.inc.php');
// some defaults for common options (these need translations)
$articleSortMethodsDefault = 'idx, pub_datum desc';
$articleSortMethods = array(
__('by index, date (newest on top)') => 'idx, pub_datum desc',
__('by index, date (oldest on top)') => 'idx, pub_datum asc',
__('manual') => 'sort_id desc'
);
$cpoRubricSettingsDefaults = array( // FIXME switch all to $cpoRubric?
'title' => '',
'sorting' => $articleSortMethodsDefault,
'edit_index' => false,
'showArchive' => false,
'showArchiveText' => __('Archive'),
'disableRubric' => false,
'disableRubricText' => '',
'edit_author' => false,
'edit_email' => false,
'edit_initial' => false,
'standard_template' => 0,
'date_format' => '',
'articleSeparator' => '',
'noArticlesFound' => __('No articles found.'),
'noOfArticles' => 10,
'language' => 'english',
'pager_showresults' => false,
'pager_found' => '',
'pager_results' => '',
'pager_previous' => '',
'pager_next' => ''
);
if (!defined('SETUP')) {
// load activated modules
$db->query('SELECT name, options FROM '.CPO_MODULES.' '
.'WHERE status='.MODULE_ACTIVE);
$activeModules = array();
while ($db->next_record()) {
$options = unserialize($db->v('options'));
if (!is_array($options)) continue;
$activeModules[$db->v('name')] = $options;
$moduleDirectory = $activeModules[$db->v('name')]['directory'];
if (@is_readable(CPO_BASEDIR.$activeModules[$db->v('name')]['directory'].'/common-module.inc.php')) {
include_once(CPO_BASEDIR.$activeModules[$db->v('name')]['directory'].'/common-module.inc.php');
continue;
}
$message[] = sprintf(
___('Unable to load module %s. The module could be missing!'),
'<em>'.htmlspecialchars($db->v('name')).'</em>'
);
}
}
// figure out and set base_url
$auto_base_url = 'http://';
if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on') {
$auto_base_url='https://';
}
if(isset($_SERVER['PHP_AUTH_USER'])) {
$auto_base_url .= $_SERVER['PHP_AUTH_USER'];
if(isset($_SERVER['PHP_AUTH_PW'])) {
$auto_base_url .= ':'.$_SERVER['PHP_AUTH_PW'];
}
$auto_base_url .= '@';
}
$auto_base_url .= $_SERVER['HTTP_HOST'];
if($_SERVER['SERVER_PORT']!=80 && $_SERVER['SERVER_PORT']!=443) {
$auto_base_url .= ':'.$_SERVER['SERVER_PORT'];
}
$DOCROOT = $_SERVER['DOCUMENT_ROOT'];
if (empty($DOCROOT)) {
$DOCROOT = substr(
str_replace(array('\\', '//'), '/', $_SERVER['PATH_TRANSLATED']),
0,
-(strlen($_SERVER['SCRIPT_NAME']))
);
}
$auto_base_url .= substr(str_replace('\\', '/', __FILE__),
strlen(str_replace('\\', '/', realpath($DOCROOT))),
-strlen('_include/2common.inc.php'));
$base_url = $cpoSystem['base_url'];
if (preg_match('=auto/?=i', $base_url) || empty($base_url)) {
$base_url = $auto_base_url;
}
// load skin configuration file
if (substr($CPO['skin'], -1)!='/') $CPO['skin'] .= '/';
if (@file_exists(CPO_BASEDIR.'_skin/'.$CPO['skin'].'common-skin.php') &&
is_readable(CPO_BASEDIR.'_skin/'.$CPO['skin'].'common-skin.php'))
include_once(CPO_BASEDIR.'_skin/'.$CPO['skin'].'common-skin.php');
// load local configuration file
if (file_exists(CPO_BASEDIR.'_cfg/common-local.inc.php') &&
is_readable(CPO_BASEDIR.'_cfg/common-local.inc.php'))
require_once(CPO_BASEDIR.'_cfg/common-local.inc.php');
if (substr($base_url, -1)!='/') $base_url .= '/';
preg_match('=^.*://[^/]*/(.*)$=', $base_url, $matches);
define('BASE_REL', '/'.$matches[1]); // relative base url
define('BASE_ABS', $base_url); // absulute base url
define('BASE_URL', $base_url); // FIXME deprecate this
if (!defined('SETUP')) define('SKIN_URL', BASE_REL.'_skin/'.$CPO['skin']);
else define('SKIN_URL', '../_skin/'.$CPO['skin']); // if the auto detection for BASE_ does not work...
// check if the setup was already done...
if (defined('SETUP') && file_exists(CPO_BASEDIR.'_cfg/db.inc.php')) {
echo ___('Looks like the setup was finished already. '
.'If you want to do the setup again, please delete the file _cfg/db.inc.php '
.'(and remove the tables in the database).');
}
?>
|