Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 94 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * PEAR_Frontend_CLI
|
3 | * PEAR_Frontend_CLI
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
8 | * that is available through the world-wide-web at the following URI:
|
8 | * that is available through the world-wide-web at the following URI:
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
10 | * the PHP License and are unable to obtain it through the web, please
|
10 | * the PHP License and are unable to obtain it through the web, please
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Stig Bakken <ssb@php.net>
|
15 | * @author Stig Bakken <ssb@php.net>
|
16 | * @author Greg Beaver <cellog@php.net>
|
16 | * @author Greg Beaver <cellog@php.net>
|
17 | * @copyright 1997-2008 The PHP Group
|
17 | * @copyright 1997-2008 The PHP Group
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
19 | * @version CVS: $Id: CLI.php,v 1.68 2008/01/03 20:26:36 cellog Exp $
|
19 | * @version CVS: $Id: CLI.php,v 1.68 2008/01/03 20:26:36 cellog Exp $
|
20 | * @link http://pear.php.net/package/PEAR
|
20 | * @link http://pear.php.net/package/PEAR
|
21 | * @since File available since Release 0.1
|
21 | * @since File available since Release 0.1
|
22 | */
|
22 | */
|
23 | /**
|
23 | /**
|
24 | * base class
|
24 | * base class
|
25 | */
|
25 | */
|
26 | require_once 'PEAR/Frontend.php'; |
26 | require_once 'PEAR/Frontend.php'; |
27 | 27 | ||
28 | /**
|
28 | /**
|
29 | * Command-line Frontend for the PEAR Installer
|
29 | * Command-line Frontend for the PEAR Installer
|
30 | * @category pear
|
30 | * @category pear
|
31 | * @package PEAR
|
31 | * @package PEAR
|
32 | * @author Stig Bakken <ssb@php.net>
|
32 | * @author Stig Bakken <ssb@php.net>
|
33 | * @author Greg Beaver <cellog@php.net>
|
33 | * @author Greg Beaver <cellog@php.net>
|
34 | * @copyright 1997-2008 The PHP Group
|
34 | * @copyright 1997-2008 The PHP Group
|
35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
36 | * @version Release: 1.7.2
|
36 | * @version Release: 1.7.2
|
37 | * @link http://pear.php.net/package/PEAR
|
37 | * @link http://pear.php.net/package/PEAR
|
38 | * @since Class available since Release 0.1
|
38 | * @since Class available since Release 0.1
|
39 | */
|
39 | */
|
40 | class PEAR_Frontend_CLI extends PEAR_Frontend |
40 | class PEAR_Frontend_CLI extends PEAR_Frontend |
41 | {
|
41 | {
|
42 | // {{{ properties
|
42 | // {{{ properties
|
43 | 43 | ||
44 | /**
|
44 | /**
|
45 | * What type of user interface this frontend is for.
|
45 | * What type of user interface this frontend is for.
|
46 | * @var string
|
46 | * @var string
|
47 | * @access public
|
47 | * @access public
|
48 | */
|
48 | */
|
49 | var $type = 'CLI'; |
49 | var $type = 'CLI'; |
50 | var $lp = ''; // line prefix |
50 | var $lp = ''; // line prefix |
51 | 51 | ||
52 | var $params = array(); |
52 | var $params = array(); |
53 | var $term = array( |
53 | var $term = array( |
54 | 'bold' => '', |
54 | 'bold' => '', |
55 | 'normal' => '', |
55 | 'normal' => '', |
56 | ); |
56 | ); |
57 | 57 | ||
58 | // }}}
|
58 | // }}}
|
59 | 59 | ||
60 | // {{{ constructor
|
60 | // {{{ constructor
|
61 | 61 | ||
62 | function PEAR_Frontend_CLI() |
62 | function PEAR_Frontend_CLI() |
63 | {
|
63 | {
|
64 | parent::PEAR(); |
64 | parent::PEAR(); |
65 | $term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1 |
65 | $term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1 |
66 | if (function_exists('posix_isatty') && !posix_isatty(1)) { |
66 | if (function_exists('posix_isatty') && !posix_isatty(1)) { |
67 | // output is being redirected to a file or through a pipe
|
67 | // output is being redirected to a file or through a pipe
|
68 | } elseif ($term) { |
68 | } elseif ($term) { |
69 | // XXX can use ncurses extension here, if available
|
69 | // XXX can use ncurses extension here, if available
|
70 | if (preg_match('/^(xterm|vt220|linux)/', $term)) { |
70 | if (preg_match('/^(xterm|vt220|linux)/', $term)) { |
71 | $this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109); |
71 | $this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109); |
72 | $this->term['normal']=sprintf("%c%c%c", 27, 91, 109); |
72 | $this->term['normal']=sprintf("%c%c%c", 27, 91, 109); |
73 | } elseif (preg_match('/^vt100/', $term)) { |
73 | } elseif (preg_match('/^vt100/', $term)) { |
74 | $this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); |
74 | $this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); |
75 | $this->term['normal']=sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0); |
75 | $this->term['normal']=sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0); |
76 | }
|
76 | }
|
77 | } elseif (OS_WINDOWS) { |
77 | } elseif (OS_WINDOWS) { |
78 | // XXX add ANSI codes here
|
78 | // XXX add ANSI codes here
|
79 | }
|
79 | }
|
80 | }
|
80 | }
|
81 | 81 | ||
82 | // }}}
|
82 | // }}}
|
83 | 83 | ||
84 | // {{{ displayLine(text)
|
84 | // {{{ displayLine(text)
|
85 | 85 | ||
86 | function displayLine($text) |
86 | function displayLine($text) |
87 | {
|
87 | {
|
88 | trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR); |
88 | trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR); |
89 | }
|
89 | }
|
90 | 90 | ||
91 | function _displayLine($text) |
91 | function _displayLine($text) |
92 | {
|
92 | {
|
93 | print "$this->lp$text\n"; |
93 | print "$this->lp$text\n"; |
94 | }
|
94 | }
|
95 | 95 | ||
96 | // }}}
|
96 | // }}}
|
97 | // {{{ display(text)
|
97 | // {{{ display(text)
|
98 | 98 | ||
99 | function display($text) |
99 | function display($text) |
100 | {
|
100 | {
|
101 | trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR); |
101 | trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR); |
102 | }
|
102 | }
|
103 | 103 | ||
104 | function _display($text) |
104 | function _display($text) |
105 | {
|
105 | {
|
106 | print $text; |
106 | print $text; |
107 | }
|
107 | }
|
108 | 108 | ||
109 | // }}}
|
109 | // }}}
|
110 | // {{{ displayError(eobj)
|
110 | // {{{ displayError(eobj)
|
111 | 111 | ||
112 | /**
|
112 | /**
|
113 | * @param object PEAR_Error object
|
113 | * @param object PEAR_Error object
|
114 | */
|
114 | */
|
115 | function displayError($eobj) |
115 | function displayError($eobj) |
116 | {
|
116 | {
|
117 | return $this->_displayLine($eobj->getMessage()); |
117 | return $this->_displayLine($eobj->getMessage()); |
118 | }
|
118 | }
|
119 | 119 | ||
120 | // }}}
|
120 | // }}}
|
121 | // {{{ displayFatalError(eobj)
|
121 | // {{{ displayFatalError(eobj)
|
122 | 122 | ||
123 | /**
|
123 | /**
|
124 | * @param object PEAR_Error object
|
124 | * @param object PEAR_Error object
|
125 | */
|
125 | */
|
126 | function displayFatalError($eobj) |
126 | function displayFatalError($eobj) |
127 | {
|
127 | {
|
128 | $this->displayError($eobj); |
128 | $this->displayError($eobj); |
129 | if (class_exists('PEAR_Config')) { |
129 | if (class_exists('PEAR_Config')) { |
130 | $config = &PEAR_Config::singleton(); |
130 | $config = &PEAR_Config::singleton(); |
131 | if ($config->get('verbose') > 5) { |
131 | if ($config->get('verbose') > 5) { |
132 | if (function_exists('debug_print_backtrace')) { |
132 | if (function_exists('debug_print_backtrace')) { |
133 | debug_print_backtrace(); |
133 | debug_print_backtrace(); |
134 | } elseif (function_exists('debug_backtrace')) { |
134 | } elseif (function_exists('debug_backtrace')) { |
135 | $trace = debug_backtrace(); |
135 | $trace = debug_backtrace(); |
136 | $raised = false; |
136 | $raised = false; |
137 | foreach ($trace as $i => $frame) { |
137 | foreach ($trace as $i => $frame) { |
138 | if (!$raised) { |
138 | if (!$raised) { |
139 | if (isset($frame['class']) && strtolower($frame['class']) == |
139 | if (isset($frame['class']) && strtolower($frame['class']) == |
140 | 'pear' && strtolower($frame['function']) == 'raiseerror') { |
140 | 'pear' && strtolower($frame['function']) == 'raiseerror') { |
141 | $raised = true; |
141 | $raised = true; |
142 | } else { |
142 | } else { |
143 | continue; |
143 | continue; |
144 | }
|
144 | }
|
145 | }
|
145 | }
|
146 | if (!isset($frame['class'])) { |
146 | if (!isset($frame['class'])) { |
147 | $frame['class'] = ''; |
147 | $frame['class'] = ''; |
148 | }
|
148 | }
|
149 | if (!isset($frame['type'])) { |
149 | if (!isset($frame['type'])) { |
150 | $frame['type'] = ''; |
150 | $frame['type'] = ''; |
151 | }
|
151 | }
|
152 | if (!isset($frame['function'])) { |
152 | if (!isset($frame['function'])) { |
153 | $frame['function'] = ''; |
153 | $frame['function'] = ''; |
154 | }
|
154 | }
|
155 | if (!isset($frame['line'])) { |
155 | if (!isset($frame['line'])) { |
156 | $frame['line'] = ''; |
156 | $frame['line'] = ''; |
157 | }
|
157 | }
|
158 | $this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]"); |
158 | $this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]"); |
159 | }
|
159 | }
|
160 | }
|
160 | }
|
161 | }
|
161 | }
|
162 | }
|
162 | }
|
163 | exit(1); |
163 | exit(1); |
164 | }
|
164 | }
|
165 | 165 | ||
166 | // }}}
|
166 | // }}}
|
167 | // {{{ displayHeading(title)
|
167 | // {{{ displayHeading(title)
|
168 | 168 | ||
169 | function displayHeading($title) |
169 | function displayHeading($title) |
170 | {
|
170 | {
|
171 | trigger_error("PEAR_Frontend_CLI::displayHeading deprecated", E_USER_ERROR); |
171 | trigger_error("PEAR_Frontend_CLI::displayHeading deprecated", E_USER_ERROR); |
172 | }
|
172 | }
|
173 | 173 | ||
174 | function _displayHeading($title) |
174 | function _displayHeading($title) |
175 | {
|
175 | {
|
176 | print $this->lp.$this->bold($title)."\n"; |
176 | print $this->lp.$this->bold($title)."\n"; |
177 | print $this->lp.str_repeat("=", strlen($title))."\n"; |
177 | print $this->lp.str_repeat("=", strlen($title))."\n"; |
178 | }
|
178 | }
|
179 | 179 | ||
180 | // }}}
|
180 | // }}}
|
181 | 181 | ||
182 | /**
|
182 | /**
|
183 | * Instruct the runInstallScript method to skip a paramgroup that matches the
|
183 | * Instruct the runInstallScript method to skip a paramgroup that matches the
|
184 | * id value passed in.
|
184 | * id value passed in.
|
185 | *
|
185 | *
|
186 | * This method is useful for dynamically configuring which sections of a post-install script
|
186 | * This method is useful for dynamically configuring which sections of a post-install script
|
187 | * will be run based on the user's setup, which is very useful for making flexible
|
187 | * will be run based on the user's setup, which is very useful for making flexible
|
188 | * post-install scripts without losing the cross-Frontend ability to retrieve user input
|
188 | * post-install scripts without losing the cross-Frontend ability to retrieve user input
|
189 | * @param string
|
189 | * @param string
|
190 | */
|
190 | */
|
191 | function skipParamgroup($id) |
191 | function skipParamgroup($id) |
192 | {
|
192 | {
|
193 | $this->_skipSections[$id] = true; |
193 | $this->_skipSections[$id] = true; |
194 | }
|
194 | }
|
195 | 195 | ||
196 | function runPostinstallScripts(&$scripts) |
196 | function runPostinstallScripts(&$scripts) |
197 | {
|
197 | {
|
198 | foreach ($scripts as $i => $script) { |
198 | foreach ($scripts as $i => $script) { |
199 | $this->runInstallScript($scripts[$i]->_params, $scripts[$i]->_obj); |
199 | $this->runInstallScript($scripts[$i]->_params, $scripts[$i]->_obj); |
200 | }
|
200 | }
|
201 | }
|
201 | }
|
202 | 202 | ||
203 | /**
|
203 | /**
|
204 | * @param array $xml contents of postinstallscript tag
|
204 | * @param array $xml contents of postinstallscript tag
|
205 | * @param object $script post-installation script
|
205 | * @param object $script post-installation script
|
206 | * @param string install|upgrade
|
206 | * @param string install|upgrade
|
207 | */
|
207 | */
|
208 | function runInstallScript($xml, &$script) |
208 | function runInstallScript($xml, &$script) |
209 | {
|
209 | {
|
210 | $this->_skipSections = array(); |
210 | $this->_skipSections = array(); |
211 | if (!is_array($xml) || !isset($xml['paramgroup'])) { |
211 | if (!is_array($xml) || !isset($xml['paramgroup'])) { |
212 | $script->run(array(), '_default'); |
212 | $script->run(array(), '_default'); |
213 | } else { |
213 | } else { |
214 | $completedPhases = array(); |
214 | $completedPhases = array(); |
215 | if (!isset($xml['paramgroup'][0])) { |
215 | if (!isset($xml['paramgroup'][0])) { |
216 | $xml['paramgroup'] = array($xml['paramgroup']); |
216 | $xml['paramgroup'] = array($xml['paramgroup']); |
217 | }
|
217 | }
|
218 | foreach ($xml['paramgroup'] as $group) { |
218 | foreach ($xml['paramgroup'] as $group) { |
219 | if (isset($this->_skipSections[$group['id']])) { |
219 | if (isset($this->_skipSections[$group['id']])) { |
220 | // the post-install script chose to skip this section dynamically
|
220 | // the post-install script chose to skip this section dynamically
|
221 | continue; |
221 | continue; |
222 | }
|
222 | }
|
223 | if (isset($group['name'])) { |
223 | if (isset($group['name'])) { |
224 | $paramname = explode('::', $group['name']); |
224 | $paramname = explode('::', $group['name']); |
225 | if ($lastgroup['id'] != $paramname[0]) { |
225 | if ($lastgroup['id'] != $paramname[0]) { |
226 | continue; |
226 | continue; |
227 | }
|
227 | }
|
228 | $group['name'] = $paramname[1]; |
228 | $group['name'] = $paramname[1]; |
229 | if (isset($answers)) { |
229 | if (isset($answers)) { |
230 | if (isset($answers[$group['name']])) { |
230 | if (isset($answers[$group['name']])) { |
231 | switch ($group['conditiontype']) { |
231 | switch ($group['conditiontype']) { |
232 | case '=' : |
232 | case '=' : |
233 | if ($answers[$group['name']] != $group['value']) { |
233 | if ($answers[$group['name']] != $group['value']) { |
234 | continue 2; |
234 | continue 2; |
235 | }
|
235 | }
|
236 | break; |
236 | break; |
237 | case '!=' : |
237 | case '!=' : |
238 | if ($answers[$group['name']] == $group['value']) { |
238 | if ($answers[$group['name']] == $group['value']) { |
239 | continue 2; |
239 | continue 2; |
240 | }
|
240 | }
|
241 | break; |
241 | break; |
242 | case 'preg_match' : |
242 | case 'preg_match' : |
243 | if (!@preg_match('/' . $group['value'] . '/', |
243 | if (!@preg_match('/' . $group['value'] . '/', |
244 | $answers[$group['name']])) { |
244 | $answers[$group['name']])) { |
245 | continue 2; |
245 | continue 2; |
246 | }
|
246 | }
|
247 | break; |
247 | break; |
248 | default : |
248 | default : |
249 | return; |
249 | return; |
250 | }
|
250 | }
|
251 | }
|
251 | }
|
252 | } else { |
252 | } else { |
253 | return; |
253 | return; |
254 | }
|
254 | }
|
255 | }
|
255 | }
|
256 | $lastgroup = $group; |
256 | $lastgroup = $group; |
257 | if (isset($group['instructions'])) { |
257 | if (isset($group['instructions'])) { |
258 | $this->_display($group['instructions']); |
258 | $this->_display($group['instructions']); |
259 | }
|
259 | }
|
260 | if (!isset($group['param'][0])) { |
260 | if (!isset($group['param'][0])) { |
261 | $group['param'] = array($group['param']); |
261 | $group['param'] = array($group['param']); |
262 | }
|
262 | }
|
263 | if (isset($group['param'])) { |
263 | if (isset($group['param'])) { |
264 | if (method_exists($script, 'postProcessPrompts')) { |
264 | if (method_exists($script, 'postProcessPrompts')) { |
265 | $prompts = $script->postProcessPrompts($group['param'], $group['id']); |
265 | $prompts = $script->postProcessPrompts($group['param'], $group['id']); |
266 | if (!is_array($prompts) || count($prompts) != count($group['param'])) { |
266 | if (!is_array($prompts) || count($prompts) != count($group['param'])) { |
267 | $this->outputData('postinstall', 'Error: post-install script did not ' . |
267 | $this->outputData('postinstall', 'Error: post-install script did not ' . |
268 | 'return proper post-processed prompts'); |
268 | 'return proper post-processed prompts'); |
269 | $prompts = $group['param']; |
269 | $prompts = $group['param']; |
270 | } else { |
270 | } else { |
271 | foreach ($prompts as $i => $var) { |
271 | foreach ($prompts as $i => $var) { |
272 | if (!is_array($var) || !isset($var['prompt']) || |
272 | if (!is_array($var) || !isset($var['prompt']) || |
273 | !isset($var['name']) || |
273 | !isset($var['name']) || |
274 | ($var['name'] != $group['param'][$i]['name']) || |
274 | ($var['name'] != $group['param'][$i]['name']) || |
275 | ($var['type'] != $group['param'][$i]['type'])) { |
275 | ($var['type'] != $group['param'][$i]['type'])) { |
276 | $this->outputData('postinstall', 'Error: post-install script ' . |
276 | $this->outputData('postinstall', 'Error: post-install script ' . |
277 | 'modified the variables or prompts, severe security risk. ' . |
277 | 'modified the variables or prompts, severe security risk. ' . |
278 | 'Will instead use the defaults from the package.xml'); |
278 | 'Will instead use the defaults from the package.xml'); |
279 | $prompts = $group['param']; |
279 | $prompts = $group['param']; |
280 | }
|
280 | }
|
281 | }
|
281 | }
|
282 | }
|
282 | }
|
283 | $answers = $this->confirmDialog($prompts); |
283 | $answers = $this->confirmDialog($prompts); |
284 | } else { |
284 | } else { |
285 | $answers = $this->confirmDialog($group['param']); |
285 | $answers = $this->confirmDialog($group['param']); |
286 | }
|
286 | }
|
287 | }
|
287 | }
|
288 | if ((isset($answers) && $answers) || !isset($group['param'])) { |
288 | if ((isset($answers) && $answers) || !isset($group['param'])) { |
289 | if (!isset($answers)) { |
289 | if (!isset($answers)) { |
290 | $answers = array(); |
290 | $answers = array(); |
291 | }
|
291 | }
|
292 | array_unshift($completedPhases, $group['id']); |
292 | array_unshift($completedPhases, $group['id']); |
293 | if (!$script->run($answers, $group['id'])) { |
293 | if (!$script->run($answers, $group['id'])) { |
294 | $script->run($completedPhases, '_undoOnError'); |
294 | $script->run($completedPhases, '_undoOnError'); |
295 | return; |
295 | return; |
296 | }
|
296 | }
|
297 | } else { |
297 | } else { |
298 | $script->run($completedPhases, '_undoOnError'); |
298 | $script->run($completedPhases, '_undoOnError'); |
299 | return; |
299 | return; |
300 | }
|
300 | }
|
301 | }
|
301 | }
|
302 | }
|
302 | }
|
303 | }
|
303 | }
|
304 | 304 | ||
305 | /**
|
305 | /**
|
306 | * Ask for user input, confirm the answers and continue until the user is satisfied
|
306 | * Ask for user input, confirm the answers and continue until the user is satisfied
|
307 | * @param array an array of arrays, format array('name' => 'paramname', 'prompt' =>
|
307 | * @param array an array of arrays, format array('name' => 'paramname', 'prompt' =>
|
308 | * 'text to display', 'type' => 'string'[, default => 'default value'])
|
308 | * 'text to display', 'type' => 'string'[, default => 'default value'])
|
309 | * @return array
|
309 | * @return array
|
310 | */
|
310 | */
|
311 | function confirmDialog($params) |
311 | function confirmDialog($params) |
312 | {
|
312 | {
|
313 | $answers = array(); |
313 | $answers = array(); |
314 | $prompts = $types = array(); |
314 | $prompts = $types = array(); |
315 | foreach ($params as $param) { |
315 | foreach ($params as $param) { |
316 | $prompts[$param['name']] = $param['prompt']; |
316 | $prompts[$param['name']] = $param['prompt']; |
317 | $types[$param['name']] = $param['type']; |
317 | $types[$param['name']] = $param['type']; |
318 | if (isset($param['default'])) { |
318 | if (isset($param['default'])) { |
319 | $answers[$param['name']] = $param['default']; |
319 | $answers[$param['name']] = $param['default']; |
320 | } else { |
320 | } else { |
321 | $answers[$param['name']] = ''; |
321 | $answers[$param['name']] = ''; |
322 | }
|
322 | }
|
323 | }
|
323 | }
|
324 | $tried = false; |
324 | $tried = false; |
325 | do { |
325 | do { |
326 | if ($tried) { |
326 | if ($tried) { |
327 | $i = 1; |
327 | $i = 1; |
328 | foreach ($answers as $var => $value) { |
328 | foreach ($answers as $var => $value) { |
329 | if (!strlen($value)) { |
329 | if (!strlen($value)) { |
330 | echo $this->bold("* Enter an answer for #" . $i . ": ({$prompts[$var]})\n"); |
330 | echo $this->bold("* Enter an answer for #" . $i . ": ({$prompts[$var]})\n"); |
331 | }
|
331 | }
|
332 | $i++; |
332 | $i++; |
333 | }
|
333 | }
|
334 | }
|
334 | }
|
335 | $answers = $this->userDialog('', $prompts, $types, $answers); |
335 | $answers = $this->userDialog('', $prompts, $types, $answers); |
336 | $tried = true; |
336 | $tried = true; |
337 | } while (is_array($answers) && count(array_filter($answers)) != count($prompts)); |
337 | } while (is_array($answers) && count(array_filter($answers)) != count($prompts)); |
338 | return $answers; |
338 | return $answers; |
339 | }
|
339 | }
|
340 | // {{{ userDialog(prompt, [type], [default])
|
340 | // {{{ userDialog(prompt, [type], [default])
|
341 | 341 | ||
342 | function userDialog($command, $prompts, $types = array(), $defaults = array(), |
342 | function userDialog($command, $prompts, $types = array(), $defaults = array(), |
343 | $screensize = 20) |
343 | $screensize = 20) |
344 | {
|
344 | {
|
345 | if (!is_array($prompts)) { |
345 | if (!is_array($prompts)) { |
346 | return array(); |
346 | return array(); |
347 | }
|
347 | }
|
348 | $testprompts = array_keys($prompts); |
348 | $testprompts = array_keys($prompts); |
349 | $result = $defaults; |
349 | $result = $defaults; |
350 | if (!defined('STDIN')) { |
350 | if (!defined('STDIN')) { |
351 | $fp = fopen('php://stdin', 'r'); |
351 | $fp = fopen('php://stdin', 'r'); |
352 | } else { |
352 | } else { |
353 | $fp = STDIN; |
353 | $fp = STDIN; |
354 | }
|
354 | }
|
355 | reset($prompts); |
355 | reset($prompts); |
356 | if (count($prompts) == 1 && $types[key($prompts)] == 'yesno') { |
356 | if (count($prompts) == 1 && $types[key($prompts)] == 'yesno') { |
357 | foreach ($prompts as $key => $prompt) { |
357 | foreach ($prompts as $key => $prompt) { |
358 | $type = $types[$key]; |
358 | $type = $types[$key]; |
359 | $default = @$defaults[$key]; |
359 | $default = @$defaults[$key]; |
360 | print "$prompt "; |
360 | print "$prompt "; |
361 | if ($default) { |
361 | if ($default) { |
362 | print "[$default] "; |
362 | print "[$default] "; |
363 | }
|
363 | }
|
364 | print ": "; |
364 | print ": "; |
365 | if (version_compare(phpversion(), '5.0.0', '<')) { |
365 | if (version_compare(phpversion(), '5.0.0', '<')) { |
366 | $line = fgets($fp, 2048); |
366 | $line = fgets($fp, 2048); |
367 | } else { |
367 | } else { |
368 | if (!defined('STDIN')) { |
368 | if (!defined('STDIN')) { |
369 | define('STDIN', fopen('php://stdin', 'r')); |
369 | define('STDIN', fopen('php://stdin', 'r')); |
370 | }
|
370 | }
|
371 | $line = fgets(STDIN, 2048); |
371 | $line = fgets(STDIN, 2048); |
372 | }
|
372 | }
|
373 | if ($default && trim($line) == "") { |
373 | if ($default && trim($line) == "") { |
374 | $result[$key] = $default; |
374 | $result[$key] = $default; |
375 | } else { |
375 | } else { |
376 | $result[$key] = trim($line); |
376 | $result[$key] = trim($line); |
377 | }
|
377 | }
|
378 | }
|
378 | }
|
379 | return $result; |
379 | return $result; |
380 | }
|
380 | }
|
381 | while (true) { |
381 | while (true) { |
382 | $descLength = max(array_map('strlen', $prompts)); |
382 | $descLength = max(array_map('strlen', $prompts)); |
383 | $descFormat = "%-{$descLength}s"; |
383 | $descFormat = "%-{$descLength}s"; |
384 | $last = count($prompts); |
384 | $last = count($prompts); |
385 | 385 | ||
386 | $i = 0; |
386 | $i = 0; |
387 | foreach ($prompts as $n => $var) { |
387 | foreach ($prompts as $n => $var) { |
388 | printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], isset($result[$n]) ? |
388 | printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], isset($result[$n]) ? |
389 | $result[$n] : null); |
389 | $result[$n] : null); |
390 | }
|
390 | }
|
391 | 391 | ||
392 | print "\n1-$last, 'all', 'abort', or Enter to continue: "; |
392 | print "\n1-$last, 'all', 'abort', or Enter to continue: "; |
393 | $tmp = trim(fgets($fp, 1024)); |
393 | $tmp = trim(fgets($fp, 1024)); |
394 | if (empty($tmp)) { |
394 | if (empty($tmp)) { |
395 | break; |
395 | break; |
396 | }
|
396 | }
|
397 | if ($tmp == 'abort') { |
397 | if ($tmp == 'abort') { |
398 | return false; |
398 | return false; |
399 | }
|
399 | }
|
400 | if (isset($testprompts[(int)$tmp - 1])) { |
400 | if (isset($testprompts[(int)$tmp - 1])) { |
401 | $var = $testprompts[(int)$tmp - 1]; |
401 | $var = $testprompts[(int)$tmp - 1]; |
402 | $desc = $prompts[$var]; |
402 | $desc = $prompts[$var]; |
403 | $current = @$result[$var]; |
403 | $current = @$result[$var]; |
404 | print "$desc [$current] : "; |
404 | print "$desc [$current] : "; |
405 | $tmp = trim(fgets($fp, 1024)); |
405 | $tmp = trim(fgets($fp, 1024)); |
406 | if (trim($tmp) !== '') { |
406 | if (trim($tmp) !== '') { |
407 | $result[$var] = trim($tmp); |
407 | $result[$var] = trim($tmp); |
408 | }
|
408 | }
|
409 | } elseif ($tmp == 'all') { |
409 | } elseif ($tmp == 'all') { |
410 | foreach ($prompts as $var => $desc) { |
410 | foreach ($prompts as $var => $desc) { |
411 | $current = $result[$var]; |
411 | $current = $result[$var]; |
412 | print "$desc [$current] : "; |
412 | print "$desc [$current] : "; |
413 | $tmp = trim(fgets($fp, 1024)); |
413 | $tmp = trim(fgets($fp, 1024)); |
414 | if (trim($tmp) !== '') { |
414 | if (trim($tmp) !== '') { |
415 | $result[$var] = trim($tmp); |
415 | $result[$var] = trim($tmp); |
416 | }
|
416 | }
|
417 | }
|
417 | }
|
418 | }
|
418 | }
|
419 | }
|
419 | }
|
420 | if (!defined('STDIN')) { |
420 | if (!defined('STDIN')) { |
421 | fclose($fp); |
421 | fclose($fp); |
422 | }
|
422 | }
|
423 | return $result; |
423 | return $result; |
424 | }
|
424 | }
|
425 | 425 | ||
426 | // }}}
|
426 | // }}}
|
427 | // {{{ userConfirm(prompt, [default])
|
427 | // {{{ userConfirm(prompt, [default])
|
428 | 428 | ||
429 | function userConfirm($prompt, $default = 'yes') |
429 | function userConfirm($prompt, $default = 'yes') |
430 | {
|
430 | {
|
431 | trigger_error("PEAR_Frontend_CLI::userConfirm not yet converted", E_USER_ERROR); |
431 | trigger_error("PEAR_Frontend_CLI::userConfirm not yet converted", E_USER_ERROR); |
432 | static $positives = array('y', 'yes', 'on', '1'); |
432 | static $positives = array('y', 'yes', 'on', '1'); |
433 | static $negatives = array('n', 'no', 'off', '0'); |
433 | static $negatives = array('n', 'no', 'off', '0'); |
434 | print "$this->lp$prompt [$default] : "; |
434 | print "$this->lp$prompt [$default] : "; |
435 | $fp = fopen("php://stdin", "r"); |
435 | $fp = fopen("php://stdin", "r"); |
436 | $line = fgets($fp, 2048); |
436 | $line = fgets($fp, 2048); |
437 | fclose($fp); |
437 | fclose($fp); |
438 | $answer = strtolower(trim($line)); |
438 | $answer = strtolower(trim($line)); |
439 | if (empty($answer)) { |
439 | if (empty($answer)) { |
440 | $answer = $default; |
440 | $answer = $default; |
441 | }
|
441 | }
|
442 | if (in_array($answer, $positives)) { |
442 | if (in_array($answer, $positives)) { |
443 | return true; |
443 | return true; |
444 | }
|
444 | }
|
445 | if (in_array($answer, $negatives)) { |
445 | if (in_array($answer, $negatives)) { |
446 | return false; |
446 | return false; |
447 | }
|
447 | }
|
448 | if (in_array($default, $positives)) { |
448 | if (in_array($default, $positives)) { |
449 | return true; |
449 | return true; |
450 | }
|
450 | }
|
451 | return false; |
451 | return false; |
452 | }
|
452 | }
|
453 | 453 | ||
454 | // }}}
|
454 | // }}}
|
455 | // {{{ startTable([params])
|
455 | // {{{ startTable([params])
|
456 | 456 | ||
457 | function startTable($params = array()) |
457 | function startTable($params = array()) |
458 | {
|
458 | {
|
459 | trigger_error("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR); |
459 | trigger_error("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR); |
460 | }
|
460 | }
|
461 | 461 | ||
462 | function _startTable($params = array()) |
462 | function _startTable($params = array()) |
463 | {
|
463 | {
|
464 | $params['table_data'] = array(); |
464 | $params['table_data'] = array(); |
465 | $params['widest'] = array(); // indexed by column |
465 | $params['widest'] = array(); // indexed by column |
466 | $params['highest'] = array(); // indexed by row |
466 | $params['highest'] = array(); // indexed by row |
467 | $params['ncols'] = 0; |
467 | $params['ncols'] = 0; |
468 | $this->params = $params; |
468 | $this->params = $params; |
469 | }
|
469 | }
|
470 | 470 | ||
471 | // }}}
|
471 | // }}}
|
472 | // {{{ tableRow(columns, [rowparams], [colparams])
|
472 | // {{{ tableRow(columns, [rowparams], [colparams])
|
473 | 473 | ||
474 | function tableRow($columns, $rowparams = array(), $colparams = array()) |
474 | function tableRow($columns, $rowparams = array(), $colparams = array()) |
475 | {
|
475 | {
|
476 | trigger_error("PEAR_Frontend_CLI::tableRow deprecated", E_USER_ERROR); |
476 | trigger_error("PEAR_Frontend_CLI::tableRow deprecated", E_USER_ERROR); |
477 | }
|
477 | }
|
478 | 478 | ||
479 | function _tableRow($columns, $rowparams = array(), $colparams = array()) |
479 | function _tableRow($columns, $rowparams = array(), $colparams = array()) |
480 | {
|
480 | {
|
481 | $highest = 1; |
481 | $highest = 1; |
482 | for ($i = 0; $i < sizeof($columns); $i++) { |
482 | for ($i = 0; $i < sizeof($columns); $i++) { |
483 | $col = &$columns[$i]; |
483 | $col = &$columns[$i]; |
484 | if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) { |
484 | if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) { |
485 | $col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0); |
485 | $col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0); |
486 | }
|
486 | }
|
487 | if (strpos($col, "\n") !== false) { |
487 | if (strpos($col, "\n") !== false) { |
488 | $multiline = explode("\n", $col); |
488 | $multiline = explode("\n", $col); |
489 | $w = 0; |
489 | $w = 0; |
490 | foreach ($multiline as $n => $line) { |
490 | foreach ($multiline as $n => $line) { |
491 | if (strlen($line) > $w) { |
491 | if (strlen($line) > $w) { |
492 | $w = strlen($line); |
492 | $w = strlen($line); |
493 | }
|
493 | }
|
494 | }
|
494 | }
|
495 | $lines = sizeof($multiline); |
495 | $lines = sizeof($multiline); |
496 | } else { |
496 | } else { |
497 | $w = strlen($col); |
497 | $w = strlen($col); |
498 | }
|
498 | }
|
499 | 499 | ||
500 | if (isset($this->params['widest'][$i])) { |
500 | if (isset($this->params['widest'][$i])) { |
501 | if ($w > $this->params['widest'][$i]) { |
501 | if ($w > $this->params['widest'][$i]) { |
502 | $this->params['widest'][$i] = $w; |
502 | $this->params['widest'][$i] = $w; |
503 | }
|
503 | }
|
504 | } else { |
504 | } else { |
505 | $this->params['widest'][$i] = $w; |
505 | $this->params['widest'][$i] = $w; |
506 | }
|
506 | }
|
507 | $tmp = count_chars($columns[$i], 1); |
507 | $tmp = count_chars($columns[$i], 1); |
508 | // handle unix, mac and windows formats
|
508 | // handle unix, mac and windows formats
|
509 | $lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1; |
509 | $lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1; |
510 | if ($lines > $highest) { |
510 | if ($lines > $highest) { |
511 | $highest = $lines; |
511 | $highest = $lines; |
512 | }
|
512 | }
|
513 | }
|
513 | }
|
514 | if (sizeof($columns) > $this->params['ncols']) { |
514 | if (sizeof($columns) > $this->params['ncols']) { |
515 | $this->params['ncols'] = sizeof($columns); |
515 | $this->params['ncols'] = sizeof($columns); |
516 | }
|
516 | }
|
517 | $new_row = array( |
517 | $new_row = array( |
518 | 'data' => $columns, |
518 | 'data' => $columns, |
519 | 'height' => $highest, |
519 | 'height' => $highest, |
520 | 'rowparams' => $rowparams, |
520 | 'rowparams' => $rowparams, |
521 | 'colparams' => $colparams, |
521 | 'colparams' => $colparams, |
522 | ); |
522 | ); |
523 | $this->params['table_data'][] = $new_row; |
523 | $this->params['table_data'][] = $new_row; |
524 | }
|
524 | }
|
525 | 525 | ||
526 | // }}}
|
526 | // }}}
|
527 | // {{{ endTable()
|
527 | // {{{ endTable()
|
528 | 528 | ||
529 | function endTable() |
529 | function endTable() |
530 | {
|
530 | {
|
531 | trigger_error("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR); |
531 | trigger_error("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR); |
532 | }
|
532 | }
|
533 | 533 | ||
534 | function _endTable() |
534 | function _endTable() |
535 | {
|
535 | {
|
536 | extract($this->params); |
536 | extract($this->params); |
537 | if (!empty($caption)) { |
537 | if (!empty($caption)) { |
538 | $this->_displayHeading($caption); |
538 | $this->_displayHeading($caption); |
539 | }
|
539 | }
|
540 | if (count($table_data) == 0) { |
540 | if (count($table_data) == 0) { |
541 | return; |
541 | return; |
542 | }
|
542 | }
|
543 | if (!isset($width)) { |
543 | if (!isset($width)) { |
544 | $width = $widest; |
544 | $width = $widest; |
545 | } else { |
545 | } else { |
546 | for ($i = 0; $i < $ncols; $i++) { |
546 | for ($i = 0; $i < $ncols; $i++) { |
547 | if (!isset($width[$i])) { |
547 | if (!isset($width[$i])) { |
548 | $width[$i] = $widest[$i]; |
548 | $width[$i] = $widest[$i]; |
549 | }
|
549 | }
|
550 | }
|
550 | }
|
551 | }
|
551 | }
|
552 | $border = false; |
552 | $border = false; |
553 | if (empty($border)) { |
553 | if (empty($border)) { |
554 | $cellstart = ''; |
554 | $cellstart = ''; |
555 | $cellend = ' '; |
555 | $cellend = ' '; |
556 | $rowend = ''; |
556 | $rowend = ''; |
557 | $padrowend = false; |
557 | $padrowend = false; |
558 | $borderline = ''; |
558 | $borderline = ''; |
559 | } else { |
559 | } else { |
560 | $cellstart = '| '; |
560 | $cellstart = '| '; |
561 | $cellend = ' '; |
561 | $cellend = ' '; |
562 | $rowend = '|'; |
562 | $rowend = '|'; |
563 | $padrowend = true; |
563 | $padrowend = true; |
564 | $borderline = '+'; |
564 | $borderline = '+'; |
565 | foreach ($width as $w) { |
565 | foreach ($width as $w) { |
566 | $borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1); |
566 | $borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1); |
567 | $borderline .= '+'; |
567 | $borderline .= '+'; |
568 | }
|
568 | }
|
569 | }
|
569 | }
|
570 | if ($borderline) { |
570 | if ($borderline) { |
571 | $this->_displayLine($borderline); |
571 | $this->_displayLine($borderline); |
572 | }
|
572 | }
|
573 | for ($i = 0; $i < sizeof($table_data); $i++) { |
573 | for ($i = 0; $i < sizeof($table_data); $i++) { |
574 | extract($table_data[$i]); |
574 | extract($table_data[$i]); |
575 | if (!is_array($rowparams)) { |
575 | if (!is_array($rowparams)) { |
576 | $rowparams = array(); |
576 | $rowparams = array(); |
577 | }
|
577 | }
|
578 | if (!is_array($colparams)) { |
578 | if (!is_array($colparams)) { |
579 | $colparams = array(); |
579 | $colparams = array(); |
580 | }
|
580 | }
|
581 | $rowlines = array(); |
581 | $rowlines = array(); |
582 | if ($height > 1) { |
582 | if ($height > 1) { |
583 | for ($c = 0; $c < sizeof($data); $c++) { |
583 | for ($c = 0; $c < sizeof($data); $c++) { |
584 | $rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]); |
584 | $rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]); |
585 | if (sizeof($rowlines[$c]) < $height) { |
585 | if (sizeof($rowlines[$c]) < $height) { |
586 | $rowlines[$c] = array_pad($rowlines[$c], $height, ''); |
586 | $rowlines[$c] = array_pad($rowlines[$c], $height, ''); |
587 | }
|
587 | }
|
588 | }
|
588 | }
|
589 | } else { |
589 | } else { |
590 | for ($c = 0; $c < sizeof($data); $c++) { |
590 | for ($c = 0; $c < sizeof($data); $c++) { |
591 | $rowlines[$c] = array($data[$c]); |
591 | $rowlines[$c] = array($data[$c]); |
592 | }
|
592 | }
|
593 | }
|
593 | }
|
594 | for ($r = 0; $r < $height; $r++) { |
594 | for ($r = 0; $r < $height; $r++) { |
595 | $rowtext = ''; |
595 | $rowtext = ''; |
596 | for ($c = 0; $c < sizeof($data); $c++) { |
596 | for ($c = 0; $c < sizeof($data); $c++) { |
597 | if (isset($colparams[$c])) { |
597 | if (isset($colparams[$c])) { |
598 | $attribs = array_merge($rowparams, $colparams); |
598 | $attribs = array_merge($rowparams, $colparams); |
599 | } else { |
599 | } else { |
600 | $attribs = $rowparams; |
600 | $attribs = $rowparams; |
601 | }
|
601 | }
|
602 | $w = isset($width[$c]) ? $width[$c] : 0; |
602 | $w = isset($width[$c]) ? $width[$c] : 0; |
603 | //$cell = $data[$c];
|
603 | //$cell = $data[$c];
|
604 | $cell = $rowlines[$c][$r]; |
604 | $cell = $rowlines[$c][$r]; |
605 | $l = strlen($cell); |
605 | $l = strlen($cell); |
606 | if ($l > $w) { |
606 | if ($l > $w) { |
607 | $cell = substr($cell, 0, $w); |
607 | $cell = substr($cell, 0, $w); |
608 | }
|
608 | }
|
609 | if (isset($attribs['bold'])) { |
609 | if (isset($attribs['bold'])) { |
610 | $cell = $this->bold($cell); |
610 | $cell = $this->bold($cell); |
611 | }
|
611 | }
|
612 | if ($l < $w) { |
612 | if ($l < $w) { |
613 | // not using str_pad here because we may
|
613 | // not using str_pad here because we may
|
614 | // add bold escape characters to $cell
|
614 | // add bold escape characters to $cell
|
615 | $cell .= str_repeat(' ', $w - $l); |
615 | $cell .= str_repeat(' ', $w - $l); |
616 | }
|
616 | }
|
617 | 617 | ||
618 | $rowtext .= $cellstart . $cell . $cellend; |
618 | $rowtext .= $cellstart . $cell . $cellend; |
619 | }
|
619 | }
|
620 | if (!$border) { |
620 | if (!$border) { |
621 | $rowtext = rtrim($rowtext); |
621 | $rowtext = rtrim($rowtext); |
622 | }
|
622 | }
|
623 | $rowtext .= $rowend; |
623 | $rowtext .= $rowend; |
624 | $this->_displayLine($rowtext); |
624 | $this->_displayLine($rowtext); |
625 | }
|
625 | }
|
626 | }
|
626 | }
|
627 | if ($borderline) { |
627 | if ($borderline) { |
628 | $this->_displayLine($borderline); |
628 | $this->_displayLine($borderline); |
629 | }
|
629 | }
|
630 | }
|
630 | }
|
631 | 631 | ||
632 | // }}}
|
632 | // }}}
|
633 | // {{{ outputData()
|
633 | // {{{ outputData()
|
634 | 634 | ||
635 | function outputData($data, $command = '_default') |
635 | function outputData($data, $command = '_default') |
636 | {
|
636 | {
|
637 | switch ($command) { |
637 | switch ($command) { |
638 | case 'channel-info': |
638 | case 'channel-info': |
639 | foreach ($data as $type => $section) { |
639 | foreach ($data as $type => $section) { |
640 | if ($type == 'main') { |
640 | if ($type == 'main') { |
641 | $section['data'] = array_values($section['data']); |
641 | $section['data'] = array_values($section['data']); |
642 | }
|
642 | }
|
643 | $this->outputData($section); |
643 | $this->outputData($section); |
644 | }
|
644 | }
|
645 | break; |
645 | break; |
646 | case 'install': |
646 | case 'install': |
647 | case 'upgrade': |
647 | case 'upgrade': |
648 | case 'upgrade-all': |
648 | case 'upgrade-all': |
649 | if (isset($data['release_warnings'])) { |
649 | if (isset($data['release_warnings'])) { |
650 | $this->_displayLine(''); |
650 | $this->_displayLine(''); |
651 | $this->_startTable(array( |
651 | $this->_startTable(array( |
652 | 'border' => false, |
652 | 'border' => false, |
653 | 'caption' => 'Release Warnings' |
653 | 'caption' => 'Release Warnings' |
654 | )); |
654 | )); |
655 | $this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55))); |
655 | $this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55))); |
656 | $this->_endTable(); |
656 | $this->_endTable(); |
657 | $this->_displayLine(''); |
657 | $this->_displayLine(''); |
658 | }
|
658 | }
|
659 | $this->_displayLine($data['data']); |
659 | $this->_displayLine($data['data']); |
660 | break; |
660 | break; |
661 | case 'search': |
661 | case 'search': |
662 | $this->_startTable($data); |
662 | $this->_startTable($data); |
663 | if (isset($data['headline']) && is_array($data['headline'])) { |
663 | if (isset($data['headline']) && is_array($data['headline'])) { |
664 | $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55))); |
664 | $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55))); |
665 | }
|
665 | }
|
666 | 666 | ||
667 | foreach($data['data'] as $category) { |
667 | foreach($data['data'] as $category) { |
668 | foreach($category as $pkg) { |
668 | foreach($category as $pkg) { |
669 | $this->_tableRow($pkg, null, array(1 => array('wrap' => 55))); |
669 | $this->_tableRow($pkg, null, array(1 => array('wrap' => 55))); |
670 | }
|
670 | }
|
671 | }; |
671 | }; |
672 | $this->_endTable(); |
672 | $this->_endTable(); |
673 | break; |
673 | break; |
674 | case 'list-all': |
674 | case 'list-all': |
675 | if (!isset($data['data'])) { |
675 | if (!isset($data['data'])) { |
676 | $this->_displayLine('No packages in channel'); |
676 | $this->_displayLine('No packages in channel'); |
677 | break; |
677 | break; |
678 | }
|
678 | }
|
679 | $this->_startTable($data); |
679 | $this->_startTable($data); |
680 | if (isset($data['headline']) && is_array($data['headline'])) { |
680 | if (isset($data['headline']) && is_array($data['headline'])) { |
681 | $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55))); |
681 | $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55))); |
682 | }
|
682 | }
|
683 | 683 | ||
684 | foreach($data['data'] as $category) { |
684 | foreach($data['data'] as $category) { |
685 | foreach($category as $pkg) { |
685 | foreach($category as $pkg) { |
686 | unset($pkg[4]); |
686 | unset($pkg[4]); |
687 | unset($pkg[5]); |
687 | unset($pkg[5]); |
688 | $this->_tableRow($pkg, null, array(1 => array('wrap' => 55))); |
688 | $this->_tableRow($pkg, null, array(1 => array('wrap' => 55))); |
689 | }
|
689 | }
|
690 | }; |
690 | }; |
691 | $this->_endTable(); |
691 | $this->_endTable(); |
692 | break; |
692 | break; |
693 | case 'config-show': |
693 | case 'config-show': |
694 | $data['border'] = false; |
694 | $data['border'] = false; |
695 | $opts = array(0 => array('wrap' => 30), |
695 | $opts = array(0 => array('wrap' => 30), |
696 | 1 => array('wrap' => 20), |
696 | 1 => array('wrap' => 20), |
697 | 2 => array('wrap' => 35)); |
697 | 2 => array('wrap' => 35)); |
698 | $this->_startTable($data); |
698 | $this->_startTable($data); |
699 | if (isset($data['headline']) && is_array($data['headline'])) { |
699 | if (isset($data['headline']) && is_array($data['headline'])) { |
700 | $this->_tableRow($data['headline'], |
700 | $this->_tableRow($data['headline'], |
701 | array('bold' => true), |
701 | array('bold' => true), |
702 | $opts); |
702 | $opts); |
703 | }
|
703 | }
|
704 | foreach($data['data'] as $group) { |
704 | foreach($data['data'] as $group) { |
705 | foreach($group as $value) { |
705 | foreach($group as $value) { |
706 | if ($value[2] == '') { |
706 | if ($value[2] == '') { |
707 | $value[2] = "<not set>"; |
707 | $value[2] = "<not set>"; |
708 | }
|
708 | }
|
709 | $this->_tableRow($value, null, $opts); |
709 | $this->_tableRow($value, null, $opts); |
710 | }
|
710 | }
|
711 | }
|
711 | }
|
712 | $this->_endTable(); |
712 | $this->_endTable(); |
713 | break; |
713 | break; |
714 | case 'remote-info': |
714 | case 'remote-info': |
715 | $d = $data; |
715 | $d = $data; |
716 | $data = array( |
716 | $data = array( |
717 | 'caption' => 'Package details:', |
717 | 'caption' => 'Package details:', |
718 | 'border' => false, |
718 | 'border' => false, |
719 | 'data' => array( |
719 | 'data' => array( |
720 | array("Latest", $data['stable']), |
720 | array("Latest", $data['stable']), |
721 | array("Installed", $data['installed']), |
721 | array("Installed", $data['installed']), |
722 | array("Package", $data['name']), |
722 | array("Package", $data['name']), |
723 | array("License", $data['license']), |
723 | array("License", $data['license']), |
724 | array("Category", $data['category']), |
724 | array("Category", $data['category']), |
725 | array("Summary", $data['summary']), |
725 | array("Summary", $data['summary']), |
726 | array("Description", $data['description']), |
726 | array("Description", $data['description']), |
727 | ), |
727 | ), |
728 | ); |
728 | ); |
729 | if (isset($d['deprecated']) && $d['deprecated']) { |
729 | if (isset($d['deprecated']) && $d['deprecated']) { |
730 | $conf = &PEAR_Config::singleton(); |
730 | $conf = &PEAR_Config::singleton(); |
731 | $reg = $conf->getRegistry(); |
731 | $reg = $conf->getRegistry(); |
732 | $name = $reg->parsedPackageNameToString($d['deprecated'], true); |
732 | $name = $reg->parsedPackageNameToString($d['deprecated'], true); |
733 | $data['data'][] = array('Deprecated! use', $name); |
733 | $data['data'][] = array('Deprecated! use', $name); |
734 | }
|
734 | }
|
735 | default: { |
735 | default: { |
736 | if (is_array($data)) { |
736 | if (is_array($data)) { |
737 | $this->_startTable($data); |
737 | $this->_startTable($data); |
738 | $count = count($data['data'][0]); |
738 | $count = count($data['data'][0]); |
739 | if ($count == 2) { |
739 | if ($count == 2) { |
740 | $opts = array(0 => array('wrap' => 25), |
740 | $opts = array(0 => array('wrap' => 25), |
741 | 1 => array('wrap' => 48) |
741 | 1 => array('wrap' => 48) |
742 | ); |
742 | ); |
743 | } elseif ($count == 3) { |
743 | } elseif ($count == 3) { |
744 | $opts = array(0 => array('wrap' => 30), |
744 | $opts = array(0 => array('wrap' => 30), |
745 | 1 => array('wrap' => 20), |
745 | 1 => array('wrap' => 20), |
746 | 2 => array('wrap' => 35) |
746 | 2 => array('wrap' => 35) |
747 | ); |
747 | ); |
748 | } else { |
748 | } else { |
749 | $opts = null; |
749 | $opts = null; |
750 | }
|
750 | }
|
751 | if (isset($data['headline']) && is_array($data['headline'])) { |
751 | if (isset($data['headline']) && is_array($data['headline'])) { |
752 | $this->_tableRow($data['headline'], |
752 | $this->_tableRow($data['headline'], |
753 | array('bold' => true), |
753 | array('bold' => true), |
754 | $opts); |
754 | $opts); |
755 | }
|
755 | }
|
756 | foreach($data['data'] as $row) { |
756 | foreach($data['data'] as $row) { |
757 | $this->_tableRow($row, null, $opts); |
757 | $this->_tableRow($row, null, $opts); |
758 | }
|
758 | }
|
759 | $this->_endTable(); |
759 | $this->_endTable(); |
760 | } else { |
760 | } else { |
761 | $this->_displayLine($data); |
761 | $this->_displayLine($data); |
762 | }
|
762 | }
|
763 | }
|
763 | }
|
764 | }
|
764 | }
|
765 | }
|
765 | }
|
766 | 766 | ||
767 | // }}}
|
767 | // }}}
|
768 | // {{{ log(text)
|
768 | // {{{ log(text)
|
769 | 769 | ||
770 | 770 | ||
771 | function log($text, $append_crlf = true) |
771 | function log($text, $append_crlf = true) |
772 | {
|
772 | {
|
773 | if ($append_crlf) { |
773 | if ($append_crlf) { |
774 | return $this->_displayLine($text); |
774 | return $this->_displayLine($text); |
775 | }
|
775 | }
|
776 | return $this->_display($text); |
776 | return $this->_display($text); |
777 | }
|
777 | }
|
778 | 778 | ||
779 | 779 | ||
780 | // }}}
|
780 | // }}}
|
781 | // {{{ bold($text)
|
781 | // {{{ bold($text)
|
782 | 782 | ||
783 | function bold($text) |
783 | function bold($text) |
784 | {
|
784 | {
|
785 | if (empty($this->term['bold'])) { |
785 | if (empty($this->term['bold'])) { |
786 | return strtoupper($text); |
786 | return strtoupper($text); |
787 | }
|
787 | }
|
788 | return $this->term['bold'] . $text . $this->term['normal']; |
788 | return $this->term['bold'] . $text . $this->term['normal']; |
789 | }
|
789 | }
|
790 | 790 | ||
791 | // }}}
|
791 | // }}}
|
792 | }
|
792 | }
|
793 | 793 | ||
794 | ?>
|
794 | ?>
|
795 | 795 |