common.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * @version $Id: common.php 1792 2015-07-12 12:09:34Z gingerdog $
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: common.php
  15. * All pages should include this file - which itself sets up the necessary
  16. * environment and ensures other functions are loaded.
  17. */
  18. if(!defined('POSTFIXADMIN')) { # already defined if called from setup.php
  19. define('POSTFIXADMIN', 1); # checked in included files
  20. if (!defined('POSTFIXADMIN_CLI')) {
  21. // this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
  22. session_cache_limiter('nocache');
  23. session_start();
  24. if (defined('POSTFIXADMIN_LOGOUT')) {
  25. session_unset();
  26. session_destroy();
  27. session_start();
  28. }
  29. if(empty($_SESSION['flash'])) {
  30. $_SESSION['flash'] = array();
  31. }
  32. }
  33. }
  34. $incpath = dirname(__FILE__);
  35. (ini_get('magic_quotes_gpc') ? ini_set('magic_quotes_runtime', '0') : '1');
  36. (ini_get('magic_quotes_gpc') ? ini_set('magic_quotes_sybase', '0') : '1');
  37. if(ini_get('register_globals') == 'on') {
  38. die("Please turn off register_globals; edit your php.ini");
  39. }
  40. /**
  41. * @param string $class
  42. * __autoload implementation, for use with spl_autoload_register().
  43. */
  44. function postfixadmin_autoload($class) {
  45. $PATH = dirname(__FILE__) . '/model/' . $class . '.php';
  46. if(is_file($PATH)) {
  47. require_once($PATH);
  48. return true;
  49. }
  50. return false;
  51. }
  52. spl_autoload_register('postfixadmin_autoload');
  53. require_once("$incpath/variables.inc.php");
  54. if(!is_file("$incpath/config.inc.php")) {
  55. die("config.inc.php is missing!");
  56. }
  57. require_once("$incpath/config.inc.php");
  58. if(isset($CONF['configured'])) {
  59. if($CONF['configured'] == FALSE) {
  60. die("Please edit config.inc.php - change \$CONF['configured'] to true after setting your database settings");
  61. }
  62. }
  63. Config::write($CONF);
  64. require_once("$incpath/languages/language.php");
  65. require_once("$incpath/functions.inc.php");
  66. if (defined('POSTFIXADMIN_CLI')) {
  67. $language = 'en'; # TODO: make configurable or autodetect from locale settings
  68. } else {
  69. $language = check_language (); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
  70. $_SESSION['lang'] = $language;
  71. }
  72. require_once("$incpath/languages/" . $language . ".lang");
  73. if(!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
  74. $hook_func = $CONF['language_hook'];
  75. $PALANG = $hook_func ($PALANG, $language);
  76. }
  77. Config::write('__LANG', $PALANG);
  78. if (!defined('POSTFIXADMIN_CLI')) {
  79. if(!is_file("$incpath/smarty.inc.php")) {
  80. die("smarty.inc.php is missing! Something is wrong...");
  81. }
  82. require_once ("$incpath/smarty.inc.php");
  83. }
  84. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  85. ?>