From 4611b111e33642f46a2d4e900cdaa969cbe38b49 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Mon, 17 Oct 2011 23:19:57 +0000 Subject: [PATCH] common.php: - merge with scripts/common.php - don't start/use session in CLI mode - don't load smarty.inc.php in CLI mode - hardcode language to 'en' in CLI mode (was done in postfixadmin-cli.php before) scripts/postfixadmin-cli.php - __bootstrap(): - use common.php instead of scripts/common.php - don't load languages/language.php and languages/en.lang (already done via common.php) - don't call language_hook (already done via common.php) scripts/common.php: - deleted - dropped helper functions low(), up(), r() and pr() which were just shortnames for existing PHP functions git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1214 a1433add-5e2c-0410-b055-b7f2511e0802 --- common.php | 32 ++++++---- scripts/common.php | 113 ----------------------------------- scripts/postfixadmin-cli.php | 11 +--- 3 files changed, 23 insertions(+), 133 deletions(-) delete mode 100644 scripts/common.php diff --git a/common.php b/common.php index 6b551d63..8d3d69a3 100644 --- a/common.php +++ b/common.php @@ -18,10 +18,13 @@ */ if(!defined('POSTFIXADMIN')) { # already defined if called from setup.php - session_start(); define('POSTFIXADMIN', 1); # checked in included files - if(empty($_SESSION['flash'])) { - $_SESSION['flash'] = array(); + + if (!defined('POSTFIXADMIN_CLI')) { + session_start(); + if(empty($_SESSION['flash'])) { + $_SESSION['flash'] = array(); + } } } @@ -48,12 +51,19 @@ if(isset($CONF['configured'])) { require_once("$incpath/languages/language.php"); require_once("$incpath/functions.inc.php"); -$_SESSION['lang'] = $language = check_language (); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-) -require_once("$incpath/languages/" . $_SESSION['lang'] . ".lang"); + +if (defined('POSTFIXADMIN_CLI')) { + $language = 'en'; # TODO: make configurable or autodetect from locale settings +} else { + $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; +} + +require_once("$incpath/languages/" . $language . ".lang"); if($CONF['language_hook'] != '' && function_exists($CONF['language_hook'])) { $hook_func = $CONF['language_hook']; - $PALANG = $hook_func ($PALANG, $_SESSION['lang']); + $PALANG = $hook_func ($PALANG, $language); } /** @@ -71,11 +81,11 @@ function postfixadmin_autoload($class) { } spl_autoload_register('postfixadmin_autoload'); -//***** -if(!is_file("$incpath/smarty.inc.php")) { - die("smarty.inc.php is missing! Something is wrong..."); +if (!defined('POSTFIXADMIN_CLI')) { + if(!is_file("$incpath/smarty.inc.php")) { + die("smarty.inc.php is missing! Something is wrong..."); + } + require_once ("$incpath/smarty.inc.php"); } -require_once ("$incpath/smarty.inc.php"); -//***** /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ ?> diff --git a/scripts/common.php b/scripts/common.php deleted file mode 100644 index 4403a500..00000000 --- a/scripts/common.php +++ /dev/null @@ -1,113 +0,0 @@ - tags around - * the output of given array. Similar to debug(). - * - * @see debug() - * @param array $var Variable to print out - * @param boolean $showFrom If set to true, the method prints from where the function was called - */ - function pr($var) { - if (Configure::read() > 0) { - echo "
";
-                        print_r($var);
-                        echo "
"; - } - } - - - - -/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 3a3b8d1d..5b125949 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -213,10 +213,8 @@ class PostfixAdmin { } $includes = array( PATH.'/config.inc.php', - PATH.'/languages/language.php', PATH.'/functions.inc.php', - PATH.'/languages/en.lang', # TODO: honor $CONF[default_language] and/or language from $_ENV - CORE_INCLUDE_PATH.'/common.php', + PATH.'/common.php', CORE_INCLUDE_PATH.'/inflector.php', ); @@ -226,16 +224,11 @@ class PostfixAdmin { return false; } } + Config::getInstance(); Config::write($CONF); Lang::getInstance(); - - if($CONF['language_hook'] != '' && function_exists($CONF['language_hook'])) { - $hook_func = $CONF['language_hook']; - $PALANG = $hook_func ($PALANG, 'en'); # $includes is also hardcoded to 'en' - see TODO above - } - Lang::write($PALANG); return true;