2025-06-22 14:16:52 +02:00
|
|
|
<?php global $basepath, $config;
|
2025-06-20 19:10:23 +02:00
|
|
|
/**
|
2025-06-22 14:16:52 +02:00
|
|
|
* Project: BeCast WebEngine - simple site engine
|
2025-06-20 19:10:23 +02:00
|
|
|
* File: init_core.inc.php
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
2025-06-22 14:16:52 +02:00
|
|
|
* @link http://www.becast.at
|
|
|
|
* @copyright 2009-2025 becast.at
|
2025-06-20 19:10:23 +02:00
|
|
|
* @author Bernhard Jaud <bernhard at becast dot at>
|
2025-06-22 14:16:52 +02:00
|
|
|
* @package BcWe core
|
2025-06-20 19:10:23 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
2025-06-22 14:16:52 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
2025-06-20 19:10:23 +02:00
|
|
|
|
2025-06-22 14:16:52 +02:00
|
|
|
const in_astat = true;
|
2025-06-20 19:10:23 +02:00
|
|
|
|
2025-06-22 14:16:52 +02:00
|
|
|
function getTime(): string
|
|
|
|
{
|
2025-06-20 19:10:23 +02:00
|
|
|
$timer = explode( ' ', microtime() );
|
2025-06-22 14:16:52 +02:00
|
|
|
return $timer[1] . $timer[0];
|
2025-06-20 19:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$start = getTime();
|
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
2025-06-22 14:24:11 +02:00
|
|
|
if(!is_file(dirname(__FILE__, 2) .'/inc/config.inc.php')){
|
|
|
|
header("Location: install/install.php");
|
|
|
|
} else {
|
|
|
|
require dirname(__FILE__, 2) . '/inc/config.inc.php';
|
|
|
|
}
|
2025-06-20 19:10:23 +02:00
|
|
|
/**
|
|
|
|
* Smarty
|
|
|
|
*/
|
|
|
|
require $basepath.'template/libs/Smarty.class.php';
|
|
|
|
use Smarty\Smarty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Database
|
|
|
|
*/
|
|
|
|
require $basepath.'database/'.$config['db_class'].'.class.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/functions.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logger
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/logger.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logger
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/datacache.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/cache.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Errors
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/error.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugins
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/plugin.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mail
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/mail.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Captcha
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/captcha.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
$plugin=new plugins();
|
|
|
|
|
|
|
|
$db= new db($config['host'], $config['user'], $config['pass'], $config['db'],'utf8', true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select $config vars form Database
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
$result = $db->query("SELECT `name`, `value` FROM `" . $config['prefix'] . "config`");
|
2025-06-20 19:10:23 +02:00
|
|
|
while ($row = $db->fetch_array($result)){
|
|
|
|
$config[$row['name']] = $row['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set LC Lang for Dates
|
|
|
|
*/
|
|
|
|
if($config['LCLANG']){
|
|
|
|
setlocale(LC_ALL,$config['LCLANG']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Datacache
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
$cache=new datacache();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Datacache
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
$ccache=new cache();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look if we have a path Variable and try to autoset if not.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if(!isset($config['path'])){
|
|
|
|
$path = explode('/', $_SERVER['SCRIPT_NAME']);
|
|
|
|
$last = array_pop($path);
|
|
|
|
$path = str_replace('/' . $last, '', $_SERVER['SCRIPT_NAME']);
|
|
|
|
$config['path'] = $path;
|
2025-06-22 14:16:52 +02:00
|
|
|
$db->query("INSERT INTO `" . $config['prefix'] . "config` (`name`, `value`, `title`, `description`, `option`, `category`) VALUES
|
2025-06-20 19:10:23 +02:00
|
|
|
( 'path', '".$path."', 'Pfad', 'Der Pfad auf ihrem Webserver z.b. /cms', 'text', 1)");
|
|
|
|
}else{
|
|
|
|
$path=$config['path'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Logger
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
$log=new logger($config['logtype'], dirname(__FILE__, 2) .'/logs/'.$config['logfile'],$config['loglevel']);
|
2025-06-20 19:10:23 +02:00
|
|
|
$tpl = new Smarty();
|
|
|
|
$error = new errorhandler();
|
|
|
|
$functions = new functions();
|
|
|
|
$root = $_SERVER['DOCUMENT_ROOT'] . $config['path'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Language
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/lang.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
$lang=new lang();
|
2025-06-22 16:46:02 +02:00
|
|
|
$lang->setlang($config['lang']);
|
2025-06-20 19:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we have a Theme variable and the Theme exists
|
|
|
|
* @TODO Theme Management
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if(isset($config['theme']) && $config['theme']!='' && is_dir($root . '/themes/'.$config['theme'])){
|
|
|
|
$tpl->setTemplateDir($root . '/themes/'.$config['theme']);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fallback
|
|
|
|
*/
|
|
|
|
$tpl->setTemplateDir($root . '/themes/default');
|
|
|
|
}
|
|
|
|
$tpl->setCompileDir($root . '/core/template/templates_c');
|
|
|
|
$tpl->setCacheDir($root . '/core/template/cache');
|
|
|
|
$tpl->setConfigDir($root . '/core/template/config');
|
2025-06-22 14:16:52 +02:00
|
|
|
try {
|
|
|
|
$tpl->registerFilter(\Smarty\Smarty::FILTER_OUTPUT, 'trimwhitespace');
|
|
|
|
$tpl->registerFilter(\Smarty\Smarty::FILTER_OUTPUT, "lang");
|
|
|
|
} catch (\Smarty\Exception $e) {
|
|
|
|
$log->write("Smarty Register Filter error", $e->getMessage());
|
|
|
|
}
|
2025-06-20 19:10:23 +02:00
|
|
|
//var_dump($tpl -> getAutoloadFilters());
|
|
|
|
/**
|
|
|
|
* Well... This should vanish with Thememanagement
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
$addnav['right'] = TRUE;
|
|
|
|
$addnav['left'] = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start Sessions
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/sessions.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
$session=new session();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate Core Class
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
require dirname(__FILE__, 2) .'/inc/core.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
$core=new core($db, $log, $tpl);
|
|
|
|
|
|
|
|
if(defined('INSTALLED')){
|
2025-06-22 14:16:52 +02:00
|
|
|
if(is_dir(dirname(__FILE__, 2) .'/install')){
|
|
|
|
$core->message($lang->_('DELINSTALLDIR'), $lang->_('DELINSTALLDIRTEXT'),FALSE);
|
|
|
|
return;
|
2025-06-20 19:10:23 +02:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
header("Location: install/install.php");
|
|
|
|
}
|
|
|
|
|
|
|
|
$captcha = new captcha();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OpenID
|
|
|
|
*/
|
|
|
|
if($config['use_openid']==1){
|
2025-06-22 14:16:52 +02:00
|
|
|
include dirname(__FILE__, 2) .'/inc/SimpleOpenID.class.php';
|
2025-06-20 19:10:23 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get all *.plugin.php files from the Modules and register the Pluginhooks
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
$core->load_modules();
|
|
|
|
foreach($core->mod_ as $key=>$val){
|
|
|
|
if(file_exists($root.'/modules/'.$val['file'].'/' . $val['file'] . '.plugins.php')){
|
|
|
|
include_once $root.'/modules/'.$val['file'].'/' . $val['file']. '.plugins.php';
|
|
|
|
$class='plugins_'.$val['file'];
|
|
|
|
if(class_exists($class)){
|
|
|
|
$imod=new $class();
|
|
|
|
if(is_callable(array($imod,'register_plugins'))){
|
|
|
|
$imod->register_plugins($plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$plugin->run_hook('init_core');
|
|
|
|
|
|
|
|
|
|
|
|
function lang($code, \Smarty\Template $template) {
|
|
|
|
$source = $code;
|
|
|
|
return preg_replace_callback ('/##(.+?)##/', 'langstr', $source);
|
|
|
|
}
|
|
|
|
|
|
|
|
function langstr($treffer)
|
|
|
|
{
|
|
|
|
global $lang;
|
|
|
|
return $lang->_($treffer[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This loads *.class.php files from the /core/modules dir.
|
|
|
|
* Its useful but "undocumented".
|
|
|
|
*
|
|
|
|
*/
|
2025-06-22 14:16:52 +02:00
|
|
|
$moduledir = dirname(__FILE__, 2) .'/core/modules';
|
2025-06-20 19:10:23 +02:00
|
|
|
$modules = opendir($moduledir);
|
|
|
|
while ($mods = readdir($modules)) {
|
|
|
|
if (preg_match('/^.*?\.class.php$/', $mods)) {
|
|
|
|
require_once($moduledir.'/'.$mods);
|
|
|
|
}
|
|
|
|
}
|
2025-06-22 14:16:52 +02:00
|
|
|
@closedir($modules);
|