symphonycms /
symphony-2
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * @package toolkit |
||||
| 5 | */ |
||||
| 6 | /** |
||||
| 7 | * Devkit extends the HTMLPage class to provide an object representation |
||||
| 8 | * of a Symphony Devkit page. Devkit's are used to aid in debugging by providing |
||||
| 9 | * raw XML representations of data sources and parameters and to help provide |
||||
| 10 | * profiling. There are two Symphony Devkit's currently, Debug and Profile. Devkit |
||||
| 11 | * pages are restricted to Symphony Author's and require them to be authenticated |
||||
| 12 | * to view them. |
||||
| 13 | */ |
||||
| 14 | |||||
| 15 | class DevKit extends HTMLPage |
||||
| 16 | { |
||||
| 17 | /** |
||||
| 18 | * The Devkit's `$_GET` query string |
||||
| 19 | * @var string |
||||
| 20 | */ |
||||
| 21 | protected $_query_string = ''; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * An instance of the XSLTPage, usually FrontendPage |
||||
| 25 | * @var XSLTPage |
||||
| 26 | */ |
||||
| 27 | protected $_page = null; |
||||
| 28 | |||||
| 29 | /** |
||||
| 30 | * An associative array of the details of the Page that is being 'Devkitted'. |
||||
| 31 | * The majority of this information is from `tbl_pages` table. |
||||
| 32 | * @var array |
||||
| 33 | */ |
||||
| 34 | protected $_pagedata = null; |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * The XML of the page that the XSLT will be applied to, this includes any |
||||
| 38 | * datasource results. |
||||
| 39 | * @var string |
||||
| 40 | */ |
||||
| 41 | protected $_xml = null; |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * An array of the page parameters, including those provided by datasources. |
||||
| 45 | * @var array |
||||
| 46 | */ |
||||
| 47 | protected $_param = array(); |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * The resulting Page after it has been transformed, as a string. This is |
||||
| 51 | * similar to what you would see if you 'view-sourced' a page in a web browser |
||||
| 52 | * @var string |
||||
| 53 | */ |
||||
| 54 | protected $_output = ''; |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * Builds the Includes for a Devkit and sets the Content Type |
||||
| 58 | * to be text/html. The default Symphony devkit stylesheet |
||||
| 59 | * is the only include. The default doctype is enables HTML5 |
||||
| 60 | */ |
||||
| 61 | protected function buildIncludes() |
||||
| 62 | { |
||||
| 63 | $this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8'); |
||||
| 64 | |||||
| 65 | $this->Html->setElementStyle('html'); |
||||
| 66 | $this->Html->setDTD('<!DOCTYPE html>'); |
||||
| 67 | $this->Html->setAttribute('lang', Lang::get()); |
||||
| 68 | $this->addElementToHead(new XMLElement( |
||||
| 69 | 'meta', |
||||
| 70 | null, |
||||
| 71 | array( |
||||
| 72 | 'http-equiv' => 'Content-Type', |
||||
| 73 | 'content' => 'text/html; charset=UTF-8' |
||||
| 74 | ) |
||||
| 75 | )); |
||||
| 76 | $this->addStylesheetToHead(ASSETS_URL . '/css/devkit.min.css', 'screen', null, false); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * This function will build the `<title>` element and create a default |
||||
| 81 | * `<h1>` with an anchor to this query string |
||||
| 82 | * |
||||
| 83 | * @param XMLElement $wrapper |
||||
| 84 | * The parent `XMLElement` to add the header to |
||||
| 85 | * @throws InvalidArgumentException |
||||
| 86 | */ |
||||
| 87 | protected function buildHeader(XMLElement $wrapper) |
||||
| 88 | { |
||||
| 89 | $this->setTitle(__( |
||||
| 90 | '%1$s – %2$s – %3$s', |
||||
| 91 | array( |
||||
| 92 | $this->_pagedata['title'], |
||||
| 93 | __($this->_title), |
||||
| 94 | __('Symphony') |
||||
| 95 | ) |
||||
| 96 | )); |
||||
| 97 | |||||
| 98 | $h1 = new XMLElement('h1'); |
||||
| 99 | $h1->appendChild(Widget::Anchor($this->_pagedata['title'], ($this->_query_string ? '?' . trim(html_entity_decode($this->_query_string), '&') : '.'))); |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | |||||
| 101 | $wrapper->appendChild($h1); |
||||
| 102 | } |
||||
| 103 | |||||
| 104 | /** |
||||
| 105 | * Using DOMDocument, construct the Navigation list using the `devkit_navigation.xml` |
||||
| 106 | * file in the `ASSETS` folder. The default navigation file is an empty `<navigation>` |
||||
| 107 | * element. The `ManipulateDevKitNavigation` delegate allows extensions |
||||
| 108 | * to inject items into the navigation. The navigation is build by iterating over `<item>` |
||||
| 109 | * elements added. The idea is that all Devkit's can be accessed using the Navigation. |
||||
| 110 | * |
||||
| 111 | * @uses ManipulateDevKitNavigation |
||||
| 112 | * @param XMLElement $wrapper |
||||
| 113 | * The parent XMLElement to add the navigation to |
||||
| 114 | * @throws InvalidArgumentException |
||||
| 115 | */ |
||||
| 116 | protected function buildNavigation(XMLElement $wrapper) |
||||
| 117 | { |
||||
| 118 | $xml = new DOMDocument(); |
||||
| 119 | $xml->preserveWhiteSpace = false; |
||||
| 120 | $xml->formatOutput = true; |
||||
| 121 | $xml->load(ASSETS . '/xml/devkit_navigation.xml'); |
||||
|
0 ignored issues
–
show
|
|||||
| 122 | $root = $xml->documentElement; |
||||
| 123 | $list = new XMLElement('ul'); |
||||
| 124 | $list->setAttribute('id', 'navigation'); |
||||
| 125 | |||||
| 126 | // Add edit link: |
||||
| 127 | $item = new XMLElement('li'); |
||||
| 128 | $item->appendChild(Widget::Anchor( |
||||
| 129 | __('Edit'), |
||||
| 130 | SYMPHONY_URL . '/blueprints/pages/edit/' . $this->_pagedata['id'] . '/' |
||||
|
0 ignored issues
–
show
|
|||||
| 131 | )); |
||||
| 132 | $list->appendChild($item); |
||||
| 133 | |||||
| 134 | // Translate navigation names: |
||||
| 135 | if ($root->hasChildNodes()) { |
||||
| 136 | foreach ($root->childNodes as $item) { |
||||
| 137 | if ($item->tagName == 'item') { |
||||
| 138 | $item->setAttribute('name', __($item->getAttribute('name'))); |
||||
| 139 | } |
||||
| 140 | } |
||||
| 141 | } |
||||
| 142 | |||||
| 143 | /** |
||||
| 144 | * Allow navigation XML to be manipulated before it is rendered. |
||||
| 145 | * |
||||
| 146 | * @delegate ManipulateDevKitNavigation |
||||
| 147 | * @param string $context |
||||
| 148 | * '/frontend/' |
||||
| 149 | * @param DOMDocument $xml |
||||
| 150 | */ |
||||
| 151 | Symphony::ExtensionManager()->notifyMembers( |
||||
| 152 | 'ManipulateDevKitNavigation', |
||||
| 153 | '/frontend/', |
||||
| 154 | array( |
||||
| 155 | 'xml' => $xml |
||||
| 156 | ) |
||||
| 157 | ); |
||||
| 158 | |||||
| 159 | if ($root->hasChildNodes()) { |
||||
| 160 | foreach ($root->childNodes as $node) { |
||||
| 161 | if ($node->getAttribute('active') === 'yes') { |
||||
| 162 | $item = new XMLElement('li', $node->getAttribute('name')); |
||||
| 163 | } else { |
||||
| 164 | $item = new XMLElement('li'); |
||||
| 165 | $item->appendChild(Widget::Anchor( |
||||
| 166 | $node->getAttribute('name'), |
||||
| 167 | '?' . $node->getAttribute('handle') . $this->_query_string |
||||
| 168 | )); |
||||
| 169 | } |
||||
| 170 | |||||
| 171 | $list->appendChild($item); |
||||
| 172 | } |
||||
| 173 | } |
||||
| 174 | |||||
| 175 | $wrapper->appendChild($list); |
||||
| 176 | } |
||||
| 177 | |||||
| 178 | /** |
||||
| 179 | * This function builds a Jump menu, which is what a Devkit uses as it's |
||||
| 180 | * internal navigation. Items are added to the Jump menu using the |
||||
| 181 | * buildJumpItem function |
||||
| 182 | * |
||||
| 183 | * @see buildJumpItem |
||||
| 184 | * @param XMLElement $wrapper |
||||
| 185 | * The parent XMLElement that the jump menu will be appended |
||||
| 186 | * to. By default this is `<div id='jump'>` |
||||
| 187 | */ |
||||
| 188 | protected function buildJump(XMLElement $wrapper) |
||||
|
0 ignored issues
–
show
The parameter
$wrapper is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 189 | { |
||||
| 190 | } |
||||
| 191 | |||||
| 192 | /** |
||||
| 193 | * |
||||
| 194 | * @param string $name |
||||
| 195 | * The name of the jump |
||||
| 196 | * @param string $link |
||||
| 197 | * The link for this jump item |
||||
| 198 | * @param boolean $active |
||||
| 199 | * Whether this is the active link, if true, this will add an |
||||
| 200 | * active class to the link built. By default this is false |
||||
| 201 | * @throws InvalidArgumentException |
||||
| 202 | * @return XMLElement |
||||
| 203 | */ |
||||
| 204 | protected function buildJumpItem($name, $link, $active = false) |
||||
|
0 ignored issues
–
show
|
|||||
| 205 | { |
||||
| 206 | $item = new XMLElement('li'); |
||||
| 207 | $anchor = Widget::Anchor($name, $link); |
||||
| 208 | $anchor->setAttribute('class', 'inactive'); |
||||
| 209 | |||||
| 210 | if ($active) { |
||||
| 211 | $anchor->setAttribute('class', 'active'); |
||||
| 212 | } |
||||
| 213 | |||||
| 214 | $item->appendChild($anchor); |
||||
| 215 | |||||
| 216 | return $item; |
||||
| 217 | } |
||||
| 218 | |||||
| 219 | /** |
||||
| 220 | * The content of the Devkit, defaults to empty. |
||||
| 221 | * |
||||
| 222 | * @param XMLElement $wrapper |
||||
| 223 | * The parent XMLElement that the content will be appended |
||||
| 224 | * to. By default this is `<div id='content'>` |
||||
| 225 | */ |
||||
| 226 | protected function buildContent(XMLElement $wrapper) |
||||
|
0 ignored issues
–
show
The parameter
$wrapper is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 227 | { |
||||
| 228 | } |
||||
| 229 | |||||
| 230 | /** |
||||
| 231 | * The prepare function acts a pseudo constructor for the Devkit, |
||||
| 232 | * setting some base variables with the given parameters |
||||
| 233 | * |
||||
| 234 | * @param XSLTPage $page |
||||
| 235 | * An instance of the XSLTPage, usually FrontendPage |
||||
| 236 | * @param array $pagedata |
||||
| 237 | * An associative array of the details of the Page that is |
||||
| 238 | * being 'Devkitted'. The majority of this information is from |
||||
| 239 | * tbl_pages table. |
||||
| 240 | * @param string $xml |
||||
| 241 | * The XML of the page that the XSLT will be applied to, this includes |
||||
| 242 | * any datasource results. |
||||
| 243 | * @param array $param |
||||
| 244 | * An array of the page parameters, including those provided by |
||||
| 245 | * datasources. |
||||
| 246 | * @param string $output |
||||
| 247 | * The resulting Page after it has been transformed, as a string. This is |
||||
| 248 | * similar to what you would see if you 'view-sourced' a page. |
||||
| 249 | */ |
||||
| 250 | public function prepare(XSLTPage $page, array $pagedata, $xml, array $param, $output) |
||||
| 251 | { |
||||
| 252 | $this->_page = $page; |
||||
| 253 | $this->_pagedata = $pagedata; |
||||
| 254 | $this->_xml = $xml; |
||||
| 255 | $this->_param = $param; |
||||
| 256 | $this->_output = $output; |
||||
| 257 | |||||
| 258 | if (is_null($this->_title)) { |
||||
| 259 | $this->_title = __('Utility'); |
||||
|
0 ignored issues
–
show
|
|||||
| 260 | } |
||||
| 261 | } |
||||
| 262 | |||||
| 263 | /** |
||||
| 264 | * Called when page is generated, this function calls each of the other |
||||
| 265 | * other functions in this page to build the Header, the Navigation, |
||||
| 266 | * the Jump menu and finally the content. This function calls it's parent |
||||
| 267 | * generate function |
||||
| 268 | * |
||||
| 269 | * @see toolkit.HTMLPage#generate() |
||||
| 270 | * @throws InvalidArgumentException |
||||
| 271 | * @return string |
||||
| 272 | */ |
||||
| 273 | public function build() |
||||
| 274 | { |
||||
| 275 | $this->buildIncludes(); |
||||
| 276 | $this->_view = General::sanitize($this->_view); |
||||
|
0 ignored issues
–
show
|
|||||
| 277 | |||||
| 278 | $header = new XMLElement('div'); |
||||
| 279 | $header->setAttribute('id', 'header'); |
||||
| 280 | $jump = new XMLElement('div'); |
||||
| 281 | $jump->setAttribute('id', 'jump'); |
||||
| 282 | $content = new XMLElement('div'); |
||||
| 283 | $content->setAttribute('id', 'content'); |
||||
| 284 | |||||
| 285 | $this->buildHeader($header); |
||||
| 286 | $this->buildNavigation($header); |
||||
| 287 | |||||
| 288 | $this->buildJump($jump); |
||||
| 289 | $header->appendChild($jump); |
||||
| 290 | |||||
| 291 | $this->Body->appendChild($header); |
||||
| 292 | |||||
| 293 | $this->buildContent($content); |
||||
| 294 | $this->Body->appendChild($content); |
||||
| 295 | |||||
| 296 | return $this->generate(); |
||||
| 297 | } |
||||
| 298 | } |
||||
| 299 |