0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00
postfixadmin/common.php

100 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2018-01-26 15:45:57 +01:00
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE.TXT.
*
* Further details on the project are available at http://postfixadmin.sf.net
*
* @license GNU GPL v2 or later.
*
* File: common.php
* All pages should include this file - which itself sets up the necessary
* environment and ensures other functions are loaded.
*/
2018-01-26 15:45:57 +01:00
if (!defined('POSTFIXADMIN')) { # already defined if called from setup.php
define('POSTFIXADMIN', 1); # checked in included files
if (!defined('POSTFIXADMIN_CLI')) {
// this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
2018-01-26 15:45:57 +01:00
session_cache_limiter('nocache');
session_name('postfixadmin_session');
session_start();
2018-01-26 15:45:57 +01:00
if (empty($_SESSION['flash'])) {
$_SESSION['flash'] = array();
}
}
}
$incpath = dirname(__FILE__);
/**
* @param string $class
* __autoload implementation, for use with spl_autoload_register().
*/
function postfixadmin_autoload($class) {
$PATH = dirname(__FILE__) . '/model/' . $class . '.php';
2018-01-26 15:45:57 +01:00
if (is_file($PATH)) {
require_once($PATH);
return true;
}
return false;
}
spl_autoload_register('postfixadmin_autoload');
2018-01-26 15:45:57 +01:00
if (!is_file("$incpath/config.inc.php")) {
die("config.inc.php is missing!");
}
2018-12-27 23:01:53 +01:00
global $CONF;
require_once("$incpath/config.inc.php");
2018-12-27 23:01:53 +01:00
2019-01-03 20:35:33 +01:00
if (isset($CONF['configured']) && !defined('PHPUNIT_TEST')) {
2018-01-26 15:45:57 +01:00
if ($CONF['configured'] == false) {
2019-01-01 21:38:07 +01:00
die("Please edit config.local.php - change \$CONF['configured'] to true after specifying appropriate local settings (database_type etc)");
}
}
Config::write($CONF);
require_once("$incpath/languages/language.php");
require_once("$incpath/functions.inc.php");
if (extension_loaded('Phar') && ( version_compare(PHP_VERSION, '7.0.0') < 0)) {
require_once("$incpath/lib/random_compat.phar");
}
if (defined('POSTFIXADMIN_CLI')) {
$language = 'en'; # TODO: make configurable or autodetect from locale settings
} else {
2018-01-26 15:45:57 +01:00
$language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
$_SESSION['lang'] = $language;
}
2018-12-28 20:31:43 +01:00
if (!empty($language)) {
2018-12-27 23:01:53 +01:00
require_once("$incpath/languages/" . $language . ".lang");
}
2018-01-26 15:45:57 +01:00
if (!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
$hook_func = $CONF['language_hook'];
2018-01-26 15:45:57 +01:00
$PALANG = $hook_func($PALANG, $language);
}
Config::write('__LANG', $PALANG);
unset($incpath);
if (!defined('POSTFIXADMIN_CLI')) {
if (!is_file(dirname(__FILE__) . "/lib/smarty.inc.php")) {
die("smarty.inc.php is missing! Something is wrong...");
}
require_once(dirname(__FILE__) . "/lib/smarty.inc.php");
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */