/
class.devkit.php
286 lines (249 loc) · 8.24 KB
/
class.devkit.php
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/**
* @package toolkit
*/
/**
* Devkit extends the HTMLPage class to provide an object representation
* of a Symphony Devkit page. Devkit's are used to aid in debugging by providing
* raw XML representations of data sources and parameters and to help provide
* profiling. There are two Symphony Devkit's currently, Debug and Profile. Devkit
* pages are restricted to Symphony Author's and require them to be authenticated
* to view them.
*/
require_once(TOOLKIT . '/class.htmlpage.php');
class DevKit extends HTMLPage {
/**
* The Devkit's `$_GET` query string
* @var string
*/
protected $_query_string = '';
/**
* An instance of the XSLTPage, usually FrontendPage
* @var XSLTPage
*/
protected $_page = null;
/**
* An associative array of the details of the Page that is being 'Devkitted'.
* The majority of this information is from `tbl_pages` table.
* @var array
*/
protected $_pagedata = null;
/**
* The XML of the page that the XSLT will be applied to, this includes any
* datasource results.
* @var string
*/
protected $_xml = null;
/**
* An array of the page parameters, including those provided by datasources.
* @var array
*/
protected $_param = array();
/**
* The resulting Page after it has been transformed, as a string. This is
* similar to what you would see if you 'view-sourced' a page in a web browser
* @var string
*/
protected $_output = '';
/**
* Builds the Includes for a Devkit and sets the Content Type
* to be text/html. The default Symphony devkit stylesheet
* is the only include. The default doctype is enables HTML5
*/
protected function buildIncludes() {
$this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$this->Html->setElementStyle('html');
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement(
'meta', null,
array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=UTF-8'
)
));
$this->addStylesheetToHead(APPLICATION_URL . '/assets/css/devkit.css', 'screen');
}
/**
* This function will build the `<title>` element and create a default
* `<h1>` with an anchor to this query string
*
* @param XMLElement $wrapper
* The parent `XMLElement` to add the header to
*/
protected function buildHeader(XMLElement $wrapper) {
$this->setTitle(__(
'%1$s – %2$s – %3$s',
array(
$this->_pagedata['title'],
__($this->_title),
__('Symphony')
)
));
$h1 = new XMLElement('h1');
$h1->appendChild(Widget::Anchor(
$this->_pagedata['title'], ($this->_query_string ? '?' . trim(html_entity_decode($this->_query_string), '&') : '.')
));
$wrapper->appendChild($h1);
}
/**
* Using DOMDocument, construct the Navigation list using the `devkit_navigation.xml`
* file in the `ASSETS` folder. The default navigation file is an empty `<navigation>`
* element. The `ManipulateDevKitNavigation` delegate allows extensions
* to inject items into the navigation. The navigation is build by iterating over `<item>`
* elements added. The idea is that all Devkit's can be accessed using the Navigation.
*
* @uses ManipulateDevKitNavigation
* @param XMLElement $wrapper
* The parent XMLElement to add the navigation to
*/
protected function buildNavigation(XMLElement $wrapper) {
$xml = new DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$xml->load(ASSETS . '/devkit_navigation.xml');
$root = $xml->documentElement;
$first = $root->firstChild;
$xpath = new DOMXPath($xml);
$list = new XMLElement('ul');
$list->setAttribute('id', 'navigation');
// Add edit link:
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
__('Edit'), SYMPHONY_URL . '/blueprints/pages/edit/' . $this->_pagedata['id'] . '/'
));
$list->appendChild($item);
// Translate navigation names:
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $item) if ($item->tagName == 'item') {
$item->setAttribute('name', __($item->getAttribute('name')));
}
}
/**
* Allow navigation XML to be manipulated before it is rendered.
*
* @delegate ManipulateDevKitNavigation
* @param string $context
* '/frontend/'
* @param DOMDocument $xml
*/
Symphony::ExtensionManager()->notifyMembers(
'ManipulateDevKitNavigation', '/frontend/',
array(
'xml' => $xml
)
);
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $node) {
if ($node->getAttribute('active') == 'yes') {
$item = new XMLElement('li', $node->getAttribute('name'));
} else {
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
$node->getAttribute('name'),
'?' . $node->getAttribute('handle') . $this->_query_string
));
}
$list->appendChild($item);
}
}
$wrapper->appendChild($list);
}
/**
* This function builds a Jump menu, which is what a Devkit uses as it's
* internal navigation. Items are added to the Jump menu using the
* buildJumpItem function
*
* @see buildJumpItem
* @param XMLElement $wrapper
* The parent XMLElement that the jump menu will be appended
* to. By default this is `<div id='jump'>`
*/
protected function buildJump(XMLElement $wrapper) { }
/**
*
* @param string $name
* The name of the jump
* @param string $link
* The link for this jump item
* @param boolean $active
* Whether this is the active link, if true, this will add an
* active class to the link built. By default this is false
* @return XMLElement
*/
protected function buildJumpItem($name, $link, $active = false) {
$item = new XMLElement('li');
$anchor = Widget::Anchor($name, $link);
$anchor->setAttribute('class', 'inactive');
if ($active == true) {
$anchor->setAttribute('class', 'active');
}
$item->appendChild($anchor);
return $item;
}
/**
* The content of the Devkit, defaults to empty.
*
* @param XMLElement $wrapper
* The parent XMLElement that the content will be appended
* to. By default this is `<div id='content'>`
*/
protected function buildContent(XMLElement $wrapper) {}
/**
* The prepare function acts a pseudo constructor for the Devkit,
* setting some base variables with the given parameters
*
* @param XSLTPage $page
* An instance of the XSLTPage, usually FrontendPage
* @param array $pagedata
* An associative array of the details of the Page that is
* being 'Devkitted'. The majority of this information is from
* tbl_pages table.
* @param string $xml
* The XML of the page that the XSLT will be applied to, this includes
* any datasource results.
* @param array $param
* An array of the page parameters, including those provided by
* datasources.
* @param string $output
* The resulting Page after it has been transformed, as a string. This is
* similar to what you would see if you 'view-sourced' a page.
*/
public function prepare(XSLTPage $page, Array $pagedata, $xml, Array $param, $output) {
$this->_page = $page;
$this->_pagedata = $pagedata;
$this->_xml = $xml;
$this->_param = $param;
$this->_output = $output;
if (is_null($this->_title)) {
$this->_title = __('Utility');
}
}
/**
* Called when page is generated, this function calls each of the other
* other functions in this page to build the Header, the Navigation,
* the Jump menu and finally the content. This function calls it's parent
* generate function
*
* @see toolkit.HTMLPage#generate()
* @return string
*/
public function build() {
$this->buildIncludes();
$this->_view = General::sanitize($this->_view);
$header = new XMLElement('div');
$header->setAttribute('id', 'header');
$jump = new XMLElement('div');
$jump->setAttribute('id', 'jump');
$content = new XMLElement('div');
$content->setAttribute('id', 'content');
$this->buildHeader($header);
$this->buildNavigation($header);
$this->buildJump($jump);
$header->appendChild($jump);
$this->Body->appendChild($header);
$this->buildContent($content);
$this->Body->appendChild($content);
return parent::generate();
}
}