2026-07-15 13:57:05 +02:00
|
|
|
<?php
|
|
|
|
|
include_once 'conf.php';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Define some app-wide constants
|
|
|
|
|
*/
|
|
|
|
|
define('ZAP_APP_BASE_DIR', realpath('.' . DIRECTORY_SEPARATOR . '..'));
|
|
|
|
|
define('ZAP_WEB_DIR', 'www');
|
|
|
|
|
define('ZAP_RESOURCE_DIR', 'resource');
|
|
|
|
|
define('ZAP_UTILS_DIR', 'utils');
|
|
|
|
|
define('ZAP_SESSIONS_DIR', 'sessions');
|
|
|
|
|
define('ZAP_LIB_DIR', 'lib');
|
|
|
|
|
define('ZAP_CONF_DIR', 'conf');
|
|
|
|
|
define('ZAP_TPL_DIR', 'tpl');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Error decoration
|
|
|
|
|
*/
|
|
|
|
|
define('ERROR_PREFIX', 'ZAP Error: ');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set include path for application
|
|
|
|
|
*/
|
|
|
|
|
function setZAPIncludePath() {
|
|
|
|
|
$app_dirs = array(ZAP_RESOURCE_DIR, ZAP_UTILS_DIR, ZAP_SESSIONS_DIR,
|
|
|
|
|
ZAP_LIB_DIR, ZAP_TPL_DIR, ZAP_CONF_DIR);
|
|
|
|
|
$app_include_path = '';
|
|
|
|
|
|
|
|
|
|
foreach ($app_dirs as $app_dir) {
|
|
|
|
|
$app_include_path .= PATH_SEPARATOR . ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR . $app_dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (set_include_path(get_include_path() . $app_include_path) == false) {
|
|
|
|
|
throw new Exception(ERROR_PREFIX . 'Error while creating include path...');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define('ZAP_INCLUDE_PATH_SET', true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initiate autoload function for application
|
|
|
|
|
*/
|
|
|
|
|
spl_autoload_register(function ($class_name) {
|
|
|
|
|
if (!defined('ZAP_INCLUDE_PATH_SET') || ZAP_INCLUDE_PATH_SET === false) {
|
|
|
|
|
try {
|
|
|
|
|
setZAPIncludePath();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo $e->getMessage();
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$include_path = get_include_path();
|
2026-07-17 12:34:37 +02:00
|
|
|
$include_path_tokens = explode(PATH_SEPARATOR, $include_path);
|
2026-07-15 13:57:05 +02:00
|
|
|
|
|
|
|
|
foreach ($include_path_tokens as $prefix) {
|
|
|
|
|
$path[0] = $prefix . DIRECTORY_SEPARATOR . $class_name . '.interface.php';
|
|
|
|
|
$path[1] = $prefix . DIRECTORY_SEPARATOR . $class_name . '.class.php';
|
|
|
|
|
|
|
|
|
|
foreach ($path as $thisPath) {
|
|
|
|
|
if (file_exists($thisPath)) {
|
|
|
|
|
require_once $thisPath;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Define remaining app-wide constants
|
|
|
|
|
*/
|
|
|
|
|
define('ZAP_MOMENT', date("Y-m-d-H_i_s"));
|
|
|
|
|
define('ZAP_VERSION', '0.9.0');
|
|
|
|
|
define('ZAP_SESSION_NAME', 'ZAP');
|
|
|
|
|
|
|
|
|
|
// Only start session in web mode (not CLI)
|
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
|
|
|
Session::start(ZAP_SESSION_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* returns string of path of template file
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getZAPTemplate($tplname) {
|
|
|
|
|
if (!defined('ZAP_APP_BASE_DIR')) {
|
|
|
|
|
throw new Exception(ERROR_PREFIX . 'No base directory defined?!');
|
|
|
|
|
}
|
|
|
|
|
$tplfile = $tplname . '.tpl';
|
|
|
|
|
$tplfilepath = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR
|
|
|
|
|
. ZAP_TPL_DIR . DIRECTORY_SEPARATOR . $tplfile;
|
|
|
|
|
if (file_exists($tplfilepath)) {
|
|
|
|
|
return $tplfilepath;
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_PREFIX . 'No template';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|