-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathRef.class.php
More file actions
executable file
·212 lines (185 loc) · 7.13 KB
/
Copy pathRef.class.php
File metadata and controls
executable file
·212 lines (185 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Reference Item class
*
* usage:
* $ref = new Ref('path_to_xml_file');
* $ref->display();
*
* includes refTableRow() function
*
* Lenny Burdette
* 2005 08 16 / 2005 08 16
*
**/
class Ref
{
var $xmlFile;
var $filepath;
var $xml;
// simple nodes
var $name;
var $category;
var $subcategory;
var $usage;
var $returns;
var $related;
var $availability;
var $partof;
var $level;
var $type;
// embedded html
var $description;
var $syntax;
var $constructor;
// optionally multiple
var $examples = array();
var $fields = array();
var $methods = array();
var $parameters = array();
var $cparameters = array();
function Ref($filename)
{
$this->filepath = $filename;
if ($this->xml =& openXML($filename)) {
$this->parse($this->xml);
}
$this->xmlFile = basename($filename);
}
function parse($xml)
{
$this->name = getValue($xml, 'name');
$this->category = getValue($xml, 'category');
$this->subcategory = getValue($xml, 'subcategory');
$this->usage = getValue($xml, 'usage');
$this->returns = getValue($xml, 'returns');
$this->related = getValue($xml, 'related');
$this->related = preg_split("/\n/", $this->related, -1, PREG_SPLIT_NO_EMPTY);
$this->availability = getValue($xml, 'availability');
$this->partof = getValue($xml, 'partof');
$this->level = getValue($xml, 'level');
$this->type = getValue($xml, 'type');
$this->hasParameter = getValue($xml, 'label'); // Added for 149
$this->hasCode = getValue($xml, 'code'); // Added for 149
$this->description = innerHTML($xml, 'description');
$this->syntax = innerHTML($xml, 'syntax');
$this->constructor = innerHTML($xml, 'constructor');
$this->examples = getFragmentsAsArray($xml, 'example', array('image', 'code'));
$this->fields = getFragmentsAsArray($xml, 'field', array('fname', 'fdescription'));
$this->methods = getFragmentsAsArray($xml, 'method', array('mname', 'mdescription'));
$this->parameters = getFragmentsAsArray($xml, 'parameter', array('label', 'description'));
$this->cparameters = getFragmentsAsArray($xml, 'cparameter', array('clabel', 'cdescription'));
}
function name()
{
$file = str_replace('.xml', '', $this->xmlFile);
$file = str_replace('_var', '', $file);
if (strstr($this->name, '()') && substr($this->name, 0, 2) != '()') {
$file .= '_';
}
$file = str_replace('convert', '', $file);
return $file .= '.html';
}
function title()
{
return (($this->type == 'Method' || $this->type == 'Field') ? $this->category . '::' : '') . $this->name;
}
function index()
{
return (strtolower($this->type) != 'method' && strtolower($this->type) != 'field');
}
function display()
{
global $lang;
$html = '<table cellpadding="0" cellspacing="0" border="0" class="ref-item">';
if ($this->type == 'Method' || $this->type == 'Field') {
$html .= refTableRow('<!--*-->Class<!--*-->', '<p>'.$this->category.'</p>');
}
$html .= refTableRow('<!--*-->Name<!--*-->', '<h3>'.$this->name.'</h3>', 'name-row');
if(!empty($this->hasCode)) { // Change for 149!
$examples = '';
$count = 0;
foreach ($this->examples as $ex) {
//echo $ex[code];
//$ex[code] = codeExampleConvert($ex[code]); // Adding this line to try to fix problems with match() and matchAll()
//echo $ex['code'];
$examples .= '<div class="example">';
$path = ($lang != 'en' ? '../media' : 'media');
$examples .= !empty($ex['image']) ? "<img src=\"$path/$ex[image]\" alt=\"example pic\" />" : '';
$examples .= !empty($ex['image']) ? "<pre class=\"margin\">$ex[code]</pre>" : "<pre>$ex[code]</pre>";
$examples .= '</div>';
if (count($this->examples) != ++$count && empty($ex['image'])) {
$examples .= '<hr class="noShade" noshade="noshade" size="1" />';
}
}
$html .= refTableRow('<!--*-->Examples<!--*-->', $examples);
}
$html .= refTableRow('<!--*-->Description<!--*-->', $this->description);
if (!empty($this->syntax)) {
$html .= refTableRow('<!--*-->Syntax<!--*-->', '<pre>'.$this->syntax.'</pre>');
}
if (!empty($this->fields)) {
$fields = '<table cellpadding="0" cellspacing="0" border="0">';
foreach ($this->fields as $f) {
$fields .= refTableRow(
"<a href=\"{$this->name}_" . convertToFilename($f['fname']) . "\">$f[fname]</a>",
$f['fdescription']
);
}
$fields .= '</table>';
$html .= refTableRow('<!--*-->Fields<!--*-->', $fields);
}
if (!empty($this->methods)) {
$methods = '<table cellpadding="0" cellspacing="0" border="0">';
foreach ($this->methods as $m) {
$methods .= refTableRow(
"<a href=\"{$this->name}_" . convertToFilename($m['mname']) . "\">$m[mname]</a>",
$m['mdescription']
);
}
$methods .= '</table>';
$html .= refTableRow('<!--*-->Methods<!--*-->', $methods);
}
if (!empty($this->constructor)) {
$html .= refTableRow('<!--*-->Constructor<!--*-->', '<pre>'.$this->constructor.'</pre>');
}
if (!empty($this->hasParameter)) { // Change for 149!
$parameters = '<table cellpadding="0" cellspacing="0" border="0">';
foreach ($this->parameters as $p) {
$parameters .= refTableRow($p['label'], $p['description']);
}
$parameters .= '</table>';
$html .= refTableRow('<!--*-->Parameters<!--*-->', $parameters);
}
if (!empty($this->cparameters)) {
$cparameters = '<table cellpadding="0" cellspacing="0" border="0">';
foreach ($this->cparameters as $c) {
$cparameters .= refTableRow($c['clabel'], $c['cdescription']);
}
$cparameters .= '</table>';
$html .= refTableRow('<!--*-->Parameters<!--*-->', $cparameters);
}
if (!empty($this->returns)) {
$html .= refTableRow('<!--*-->Returns<!--*-->', $this->returns);
}
$html .= refTableRow('<!--*-->Usage<!--*-->', $this->usage);
if (!empty($this->related)) {
$related = '';
foreach ($this->related as $r) {
$related .= '<a href="' . convertToFilename($r) . '">' . $r . '</a><br />';
}
$html .= refTableRow('<!--*-->Related<!--*-->', $related);
}
$html .= '</table>';
return $html;
}
}
function refTableRow($label, $data, $class = '')
{
$html = "\n\t<tr class=\"$class\">\n";
$html .= "\t\t<th scope=\"row\">$label</th>\n";
$html .= "\t\t<td>$data</td>\n";
$html .= "\t</tr>\n";
return $html;
}
?>