143 $this->_skipSections = array();
144 if (!is_array($xml) || !isset($xml[
'paramgroup'])) {
145 $script->run(array(),
'_default');
149 $completedPhases = array();
150 if (!isset($xml[
'paramgroup'][0])) {
151 $xml[
'paramgroup'] = array($xml[
'paramgroup']);
154 foreach ($xml[
'paramgroup'] as $group) {
155 if (isset($this->_skipSections[$group[
'id']])) {
160 if (isset($group[
'name'])) {
161 $paramname = explode(
'::', $group[
'name']);
162 if ($lastgroup[
'id'] != $paramname[0]) {
166 $group[
'name'] = $paramname[1];
167 if (!isset($answers)) {
171 if (isset($answers[$group[
'name']])) {
172 switch ($group[
'conditiontype']) {
174 if ($answers[$group[
'name']] != $group[
'value']) {
179 if ($answers[$group[
'name']] == $group[
'value']) {
184 if (!@preg_match(
'/' . $group[
'value'] .
'/',
185 $answers[$group[
'name']])) {
196 if (isset($group[
'instructions'])) {
197 $this->
_display($group[
'instructions']);
200 if (!isset($group[
'param'][0])) {
201 $group[
'param'] = array($group[
'param']);
204 if (isset($group[
'param'])) {
205 if (method_exists($script,
'postProcessPrompts')) {
206 $prompts = $script->postProcessPrompts($group[
'param'], $group[
'id']);
207 if (!is_array($prompts) || count($prompts) != count($group[
'param'])) {
208 $this->
outputData(
'postinstall',
'Error: post-install script did not ' .
209 'return proper post-processed prompts');
210 $prompts = $group[
'param'];
212 foreach ($prompts as $i => $var) {
213 if (!is_array($var) || !isset($var[
'prompt']) ||
214 !isset($var[
'name']) ||
215 ($var[
'name'] != $group[
'param'][$i][
'name']) ||
216 ($var[
'type'] != $group[
'param'][$i][
'type'])
218 $this->
outputData(
'postinstall',
'Error: post-install script ' .
219 'modified the variables or prompts, severe security risk. ' .
220 'Will instead use the defaults from the package.xml');
221 $prompts = $group[
'param'];
232 if ((isset($answers) && $answers) || !isset($group[
'param'])) {
233 if (!isset($answers)) {
237 array_unshift($completedPhases, $group[
'id']);
238 if (!$script->run($answers, $group[
'id'])) {
239 $script->run($completedPhases,
'_undoOnError');
243 $script->run($completedPhases,
'_undoOnError');
257 $answers = $prompts = $types = array();
259 $prompts[$param[
'name']] = $param[
'prompt'];
260 $types[$param[
'name']] = $param[
'type'];
261 $answers[$param[
'name']] = isset($param[
'default']) ? $param[
'default'] :
'';
268 foreach ($answers as $var => $value) {
269 if (!strlen($value)) {
270 echo $this->
bold(
"* Enter an answer for #" . $i .
": ({$prompts[$var]})\n");
276 $answers = $this->
userDialog(
'', $prompts, $types, $answers);
278 }
while (is_array($answers) && count(array_filter($answers)) != count($prompts));
285 if (!is_array($prompts)) {
289 $testprompts = array_keys($prompts);
293 if (count($prompts) === 1) {
294 foreach ($prompts as $key => $prompt) {
295 $type = $types[$key];
296 $default = @$defaults[$key];
303 $line = fgets(STDIN, 2048);
304 $result[$key] = ($default && trim($line) ==
'') ? $default : trim($line);
312 $descLength = max(array_map(
'strlen', $prompts));
313 $descFormat =
"%-{$descLength}s";
314 $last = count($prompts);
317 foreach ($prompts as $n => $var) {
319 printf(
"%2d. $descFormat : %s\n", ++$i, $prompts[$n], $res);
321 print
"\n1-$last, 'all', 'abort', or Enter to continue: ";
323 $tmp = trim(fgets(STDIN, 1024));
328 if ($tmp ==
'abort') {
332 if (isset($testprompts[(
int)$tmp - 1])) {
333 $var = $testprompts[(int)$tmp - 1];
334 $desc = $prompts[$var];
336 print
"$desc [$current] : ";
337 $tmp = trim(fgets(STDIN, 1024));
341 } elseif ($tmp ==
'all') {
342 foreach ($prompts as $var => $desc) {
344 print
"$desc [$current] : ";
345 $tmp = trim(fgets(STDIN, 1024));
346 if (trim($tmp) !==
'') {
360 if (PHP_VERSION_ID < 70000) {
361 trigger_error(
"PEAR_Frontend_CLI::userConfirm not yet converted",
E_USER_ERROR);
363 throw new Error(
'PEAR_Frontend_CLI::userConfirm not yet converted');
365 static $positives = array(
'y',
'yes',
'on',
'1');
366 static $negatives = array(
'n',
'no',
'off',
'0');
367 print
"$this->lp$prompt [$default] : ";
368 $fp = fopen(
"php://stdin",
"r");
369 $line = fgets($fp, 2048);
371 $answer = strtolower(trim($line));
372 if (empty($answer)) {
375 if (in_array($answer, $positives)) {
378 if (in_array($answer, $negatives)) {
381 if (in_array($default, $positives)) {
391 foreach ($data as
$type => $section) {
392 if (
$type ==
'main') {
393 $section[
'data'] = array_values($section[
'data']);
402 if (is_array($data) && isset($data[
'release_warnings'])) {
406 'caption' =>
'Release Warnings'
408 $this->
_tableRow(array($data[
'release_warnings']),
null, array(1 => array(
'wrap' => 55)));
413 $this->
_displayLine(is_array($data) ? $data[
'data'] : $data);
417 if (isset($data[
'headline']) && is_array($data[
'headline'])) {
418 $this->
_tableRow($data[
'headline'], array(
'bold' =>
true), array(1 => array(
'wrap' => 55)));
422 foreach($data[
'data'] as $category) {
423 foreach($category as $name => $pkg) {
424 $packages[$pkg[0]] = $pkg;
428 $p = array_keys($packages);
430 foreach ($p as $name) {
431 $this->
_tableRow($packages[$name],
null, array(1 => array(
'wrap' => 55)));
437 if (!isset($data[
'data'])) {
443 if (isset($data[
'headline']) && is_array($data[
'headline'])) {
444 $this->
_tableRow($data[
'headline'], array(
'bold' =>
true), array(1 => array(
'wrap' => 55)));
448 foreach($data[
'data'] as $category) {
449 foreach($category as $name => $pkg) {
450 $packages[$pkg[0]] = $pkg;
454 $p = array_keys($packages);
456 foreach ($p as $name) {
457 $pkg = $packages[$name];
458 unset($pkg[4], $pkg[5]);
459 $this->
_tableRow($pkg,
null, array(1 => array(
'wrap' => 55)));
465 $data[
'border'] =
false;
467 0 => array(
'wrap' => 30),
468 1 => array(
'wrap' => 20),
469 2 => array(
'wrap' => 35)
473 if (isset($data[
'headline']) && is_array($data[
'headline'])) {
474 $this->
_tableRow($data[
'headline'], array(
'bold' =>
true),
$opts);
477 foreach ($data[
'data'] as $group) {
478 foreach ($group as $value) {
479 if ($value[2] ==
'') {
480 $value[2] =
"<not set>";
492 'caption' =>
'Package details:',
495 array(
"Latest", $data[
'stable']),
496 array(
"Installed", $data[
'installed']),
497 array(
"Package", $data[
'name']),
498 array(
"License", $data[
'license']),
499 array(
"Category", $data[
'category']),
500 array(
"Summary", $data[
'summary']),
501 array(
"Description", $data[
'description']),
505 if (isset($d[
'deprecated']) && $d[
'deprecated']) {
506 $conf = &PEAR_Config::singleton();
507 $reg = $conf->getRegistry();
508 $name = $reg->parsedPackageNameToString($d[
'deprecated'],
true);
509 $data[
'data'][] = array(
'Deprecated! use', $name);
512 if (is_array($data)) {
514 $count = count($data[
'data'][0]);
516 $opts = array(0 => array(
'wrap' => 25),
517 1 => array(
'wrap' => 48)
519 } elseif ($count == 3) {
520 $opts = array(0 => array(
'wrap' => 30),
521 1 => array(
'wrap' => 20),
522 2 => array(
'wrap' => 35)
527 if (isset($data[
'headline']) && is_array($data[
'headline'])) {
529 array(
'bold' =>
true),
533 if (is_array($data[
'data'])) {
534 foreach($data[
'data'] as $row) {
581 function _tableRow($columns, $rowparams = array(), $colparams = array())
584 for ($i = 0; $i < count($columns); $i++) {
585 $col = &$columns[$i];
586 if (isset($colparams[$i]) && !empty($colparams[$i][
'wrap'])) {
587 $col = wordwrap($col, $colparams[$i][
'wrap']);
590 if (strpos($col,
"\n") !==
false) {
591 $multiline = explode(
"\n", $col);
593 foreach ($multiline as $n => $line) {
594 $len = strlen($line);
599 $lines = count($multiline);
604 if (isset($this->params[
'widest'][$i])) {
605 if ($w > $this->params[
'widest'][$i]) {
606 $this->params[
'widest'][$i] = $w;
609 $this->params[
'widest'][$i] = $w;
612 $tmp = count_chars($columns[$i], 1);
614 $lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1;
615 if ($lines > $highest) {
620 if (count($columns) > $this->params[
'ncols']) {
621 $this->params[
'ncols'] = count($columns);
626 'height' => $highest,
627 'rowparams' => $rowparams,
628 'colparams' => $colparams,
630 $this->params[
'table_data'][] = $new_row;
635 extract($this->params);
636 if (!empty($caption)) {
640 if (count($table_data) === 0) {
644 if (!isset($width)) {
647 for ($i = 0; $i < $ncols; $i++) {
648 if (!isset($width[$i])) {
649 $width[$i] = $widest[$i];
655 if (empty($border)) {
667 foreach ($width as $w) {
668 $borderline .= str_repeat(
'-', $w + strlen($cellstart) + strlen($cellend) - 1);
677 for ($i = 0; $i < count($table_data); $i++) {
678 extract($table_data[$i]);
679 if (!is_array($rowparams)) {
680 $rowparams = array();
683 if (!is_array($colparams)) {
684 $colparams = array();
689 for ($c = 0; $c < count($data); $c++) {
690 $rowlines[$c] = preg_split(
'/(\r?\n|\r)/', $data[$c]);
691 if (count($rowlines[$c]) < $height) {
692 $rowlines[$c] = array_pad($rowlines[$c], $height,
'');
696 for ($c = 0; $c < count($data); $c++) {
697 $rowlines[$c] = array($data[$c]);
701 for ($r = 0; $r < $height; $r++) {
703 for ($c = 0; $c < count($data); $c++) {
704 if (isset($colparams[$c])) {
705 $attribs = array_merge($rowparams, $colparams);
707 $attribs = $rowparams;
710 $w = isset($width[$c]) ? $width[$c] : 0;
712 $cell = $rowlines[$c][$r];
715 $cell = substr($cell, 0, $w);
718 if (isset($attribs[
'bold'])) {
719 $cell = $this->
bold($cell);
725 $cell .= str_repeat(
' ', $w - $l);
728 $rowtext .= $cellstart . $cell . $cellend;
732 $rowtext = rtrim($rowtext);