| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* @category Pear
|
|
|
4 |
* @package PEAR_Frontend_Web
|
|
|
5 |
* @author Tias Guns <tias@ulyssis.org>
|
|
|
6 |
* @copyright 1997-2007 The PHP Group
|
|
|
7 |
* @license http://www.php.net/license/2_02.txt PHP License 2.02
|
|
|
8 |
* @version CVS: $Id: Docviewer.php 235933 2007-05-19 15:36:40Z tias $
|
|
|
9 |
* @link http://pear.php.net/package/PEAR_Frontend_Web
|
|
|
10 |
* @since File available since Release 0.6.2
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* PEAR_Frontend_Web_Docviewer allows you to view the documentation
|
|
|
15 |
* of the installed packages, in the webfrontend.
|
|
|
16 |
*
|
|
|
17 |
* Most packages provide some documentation files, this class allows
|
|
|
18 |
* you to find out which ones, and to display there content.
|
|
|
19 |
*
|
|
|
20 |
* @category Pear
|
|
|
21 |
* @package PEAR_Frontend_Web
|
|
|
22 |
* @author Tias Guns <tias@ulyssis.org>
|
|
|
23 |
* @copyright 1997-2007 The PHP Group
|
|
|
24 |
* @license http://www.php.net/license/2_02.txt PHP License 2.02
|
|
|
25 |
* @version CVS: $Id: Docviewer.php 235933 2007-05-19 15:36:40Z tias $
|
|
|
26 |
* @link http://pear.php.net/package/PEAR_Frontend_Web
|
|
|
27 |
* @since File available since Release 0.6.2
|
|
|
28 |
*/
|
|
|
29 |
class PEAR_Frontend_Web_Docviewer
|
|
|
30 |
{
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* The config object
|
|
|
34 |
*/
|
|
|
35 |
var $config;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* User Interface object, for all interaction with the user.
|
|
|
39 |
* @var object
|
|
|
40 |
*/
|
|
|
41 |
var $ui;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Create instance and set config to global frontweb config
|
|
|
45 |
*
|
|
|
46 |
* @param $ui User Interface object
|
|
|
47 |
*/
|
|
|
48 |
function PEAR_Frontend_Web_Docviewer(&$ui)
|
|
|
49 |
{
|
|
|
50 |
$this->config = &$GLOBALS['_PEAR_Frontend_Web_config'];
|
|
|
51 |
$this->ui = &$ui;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Set the config, manually
|
|
|
56 |
*
|
|
|
57 |
* @param $config config object
|
|
|
58 |
*/
|
|
|
59 |
function setConfig(&$config)
|
|
|
60 |
{
|
|
|
61 |
$this->config = &$config;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Get the files with role 'doc' of the given package
|
|
|
66 |
*
|
|
|
67 |
* Can be called as static method
|
|
|
68 |
*
|
|
|
69 |
* @param string $package package name
|
|
|
70 |
* @param string $channel
|
|
|
71 |
* @return array('name' => 'installed_as', ...
|
|
|
72 |
*/
|
|
|
73 |
function getDocFiles($package_name, $channel)
|
|
|
74 |
{
|
|
|
75 |
$reg = $this->config->getRegistry();
|
|
|
76 |
$files_all = $reg->packageInfo($package_name, 'filelist', $channel);
|
|
|
77 |
$files_doc = array();
|
|
|
78 |
foreach($files_all as $name => $file) {
|
|
|
79 |
if ($file['role'] == 'doc') {
|
|
|
80 |
$files_doc[$name] = $file['installed_as'];
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
return $files_doc;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Output in HTML the list of docs of given package
|
|
|
88 |
*
|
|
|
89 |
* @param string $package package name
|
|
|
90 |
* @param string $channel
|
|
|
91 |
* @return true (uses the User Interface object)
|
|
|
92 |
*/
|
|
|
93 |
function outputListDocs($package_name, $channel)
|
|
|
94 |
{
|
|
|
95 |
$command = 'list-docs';
|
|
|
96 |
$data = array(
|
|
|
97 |
'caption' => 'Package '.$channel.'/'.$package_name.', Documentation files:',
|
|
|
98 |
'border' => true,
|
|
|
99 |
'headline' => array('File', 'Location'),
|
|
|
100 |
'channel' => $channel,
|
|
|
101 |
'package' => $package_name,
|
|
|
102 |
);
|
|
|
103 |
|
|
|
104 |
$files = $this->getDocFiles($package_name, $channel);
|
|
|
105 |
if (count($files) == 0) {
|
|
|
106 |
$data['data'] = '(no documentation available)';
|
|
|
107 |
} else {
|
|
|
108 |
foreach ($files as $name => $location) {
|
|
|
109 |
$data['data'][$name] = $location;
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
$this->ui->outputData($data, $command);
|
|
|
113 |
|
|
|
114 |
return true;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Output in HTML the documentation file of given package
|
|
|
119 |
*
|
|
|
120 |
* @param string $package package name
|
|
|
121 |
* @param string $channel
|
|
|
122 |
* @param string $file
|
|
|
123 |
* @return true (uses the User Interface object)
|
|
|
124 |
*/
|
|
|
125 |
function outputDocShow($package_name, $channel, $file)
|
|
|
126 |
{
|
|
|
127 |
$this->outputListDocs($package_name, $channel);
|
|
|
128 |
|
|
|
129 |
$command = 'doc-show';
|
|
|
130 |
$data = array(
|
|
|
131 |
'caption' => $channel.'/'.$package_name.' :: '.$file.':',
|
|
|
132 |
'border' => true,
|
|
|
133 |
'channel' => $channel,
|
|
|
134 |
'package' => $package_name,
|
|
|
135 |
);
|
|
|
136 |
|
|
|
137 |
$files = $this->getDocFiles($package_name, $channel);
|
|
|
138 |
if (!isset($files[$file])) {
|
|
|
139 |
$data['data'] = 'File '.$file.' is not part of the documentation of this package.';
|
|
|
140 |
} else {
|
|
|
141 |
$data['data'] = file_get_contents($files[$file]);
|
|
|
142 |
//$data['data'] = $file;
|
|
|
143 |
}
|
|
|
144 |
$this->ui->outputData($data, $command);
|
|
|
145 |
|
|
|
146 |
return true;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
?>
|