common.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @license GNU GPL v2 or later.
  12. *
  13. * File: common.php
  14. * All pages should include this file - which itself sets up the necessary
  15. * environment and ensures other functions are loaded.
  16. */
  17. if (!defined('POSTFIXADMIN')) { # already defined if called from setup.php
  18. define('POSTFIXADMIN', 1); # checked in included files
  19. if (!defined('POSTFIXADMIN_CLI')) {
  20. // this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
  21. session_cache_limiter('nocache');
  22. session_name('postfixadmin_session');
  23. session_start();
  24. if (empty($_SESSION['flash'])) {
  25. $_SESSION['flash'] = array();
  26. }
  27. }
  28. }
  29. $incpath = dirname(__FILE__);
  30. /**
  31. * @param string $class
  32. * __autoload implementation, for use with spl_autoload_register().
  33. */
  34. function postfixadmin_autoload($class) {
  35. $PATH = dirname(__FILE__) . '/model/' . $class . '.php';
  36. if (is_file($PATH)) {
  37. require_once($PATH);
  38. return true;
  39. }
  40. return false;
  41. }
  42. spl_autoload_register('postfixadmin_autoload');
  43. if (!is_file("$incpath/config.inc.php")) {
  44. die("config.inc.php is missing!");
  45. }
  46. global $CONF;
  47. require_once("$incpath/config.inc.php");
  48. if (isset($CONF['configured']) && !defined('PHPUNIT_TEST')) {
  49. if ($CONF['configured'] == false) {
  50. die("Please edit config.local.php - change \$CONF['configured'] to true after specifying appropriate local settings (database_type etc)");
  51. }
  52. }
  53. Config::getInstance()->setAll($CONF);
  54. $PALANG = [];
  55. require_once("$incpath/languages/language.php");
  56. require_once("$incpath/functions.inc.php");
  57. if (defined('POSTFIXADMIN_CLI')) {
  58. $language = 'en'; # TODO: make configurable or autodetect from locale settings
  59. } else {
  60. $language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
  61. $_SESSION['lang'] = $language;
  62. }
  63. if (!empty($language)) {
  64. require_once("$incpath/languages/" . $language . ".lang");
  65. }
  66. if (!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
  67. $hook_func = $CONF['language_hook'];
  68. $PALANG = $hook_func($PALANG, $language);
  69. }
  70. Config::write('__LANG', $PALANG);
  71. if (!defined('POSTFIXADMIN_CLI')) {
  72. if (!isset($PALANG)) {
  73. die("environment not setup correctly");
  74. }
  75. require_once(__DIR__ . '/lib/smarty/libs/Autoloader.php');
  76. Smarty_Autoloader::register();
  77. }
  78. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */