function GetParams(&$Config, $IsCLI) { //Get CLI arguments $ARGs = array(); $ParameterDescriptions = GetParametersInfo($Config); if ($IsCLI) { $LongOptions = $ShortOptions = array(); foreach ($ParameterDescriptions as $PD) { $OptionalColon = isset($PD[5]) && $PD[5] ? '' : ':'; //Only add colons for required parameters $ShortOptions[] = $PD[0] . $OptionalColon; $LongOptions[] = $PD[1] . $OptionalColon; } $ARGs = cgetopt(implode('', $ShortOptions), $LongOptions); } //Combine arguments $Params = array(); //Final parameters, all named by the HTMLName foreach ($ParameterDescriptions as $PD) { if ($IsCLI && (isset($ARGs[$PD[0]]) || isset($ARGs[$PD[1]]))) { $Params[$PD[2]] = $ARGs[$PD[isset($ARGs[$PD[0]]) ? 0 : 1]]; } else { if (!$IsCLI && isset($_REQUEST[$PD[2]])) { $Params[$PD[2]] = $_REQUEST[$PD[2]]; } } } return $Params; }
EndText; //Get the last PHP error for user output //This is required b/c PHP ~<5.3 does not allow direct array access from a function return function GetLastError() { $E = error_get_last(); return $E['message']; } //Confirm PHP version if (version_compare(PHP_VERSION, '5.3.0', '<')) { return OL('Requires PHP>=5.2.4 for the \\h PREG character set; php>=5.3.0 for anonymous functions'); } //Output the help if requested or required global $IsCLI; if ($IsCLI) { global $argc; require_once __DIR__ . '/CustomGetOpt.php'; } if ($IsCLI && ($argc < 2 || count(cgetopt('h', array('help')))) || !$IsCLI && (isset($_REQUEST['Help']) || !count(array_merge($_GET, $_POST)))) { //Output the program description global $ConfigVars; OL(str_ireplace('?AllowConfigOverride?', $ConfigVars['AllowConfigOverride'] ? 'On' : 'Off', $ProgramDescription), 'Normal', false); //Output the parameters require_once __DIR__ . '/Parameters.php'; foreach (GetParametersInfo($ConfigVars) as $PD) { OL('* ' . ($IsCLI ? "-{$PD['0']} --{$PD['1']}" : $PD[2]) . "{$PD['3']}:" . implode("\n ", array_merge(array(''), !is_array($PD[4]) ? array($PD[4]) : $PD[4])), 'Normal', false); } //Nothing left to do after the help prompt return 1; } return 0;