| Total Complexity | 130 |
| Total Lines | 983 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like contentBlueprintsPages often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use contentBlueprintsPages, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class contentBlueprintsPages extends AdministrationPage |
||
|
|
|||
| 14 | { |
||
| 15 | public $_errors = array(); |
||
| 16 | protected $_hilights = array(); |
||
| 17 | |||
| 18 | public function insertBreadcrumbsUsingPageIdentifier($page_id, $preserve_last = true) |
||
| 19 | { |
||
| 20 | if ($page_id == 0) { |
||
| 21 | return $this->insertBreadcrumbs( |
||
| 22 | array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/')) |
||
| 23 | ); |
||
| 24 | } |
||
| 25 | |||
| 26 | $pages = PageManager::resolvePage($page_id, 'handle'); |
||
| 27 | |||
| 28 | foreach ($pages as &$page) { |
||
| 29 | // If we are viewing the Page Editor, the Breadcrumbs should link |
||
| 30 | // to the parent's Page Editor. |
||
| 31 | if ($this->_context[0] == 'edit') { |
||
| 32 | $page = Widget::Anchor( |
||
| 33 | General::sanitize(PageManager::fetchTitleFromHandle($page)), |
||
| 34 | SYMPHONY_URL . '/blueprints/pages/edit/' . PageManager::fetchIDFromHandle($page) . '/' |
||
| 35 | ); |
||
| 36 | |||
| 37 | // If the pages index is nested, the Breadcrumb should link to the |
||
| 38 | // Pages Index filtered by parent |
||
| 39 | } elseif (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes') { |
||
| 40 | $page = Widget::Anchor( |
||
| 41 | General::sanitize(PageManager::fetchTitleFromHandle($page)), |
||
| 42 | SYMPHONY_URL . '/blueprints/pages/?parent=' . PageManager::fetchIDFromHandle($page) |
||
| 43 | ); |
||
| 44 | |||
| 45 | // If there is no nesting on the Pages Index, the breadcrumb is |
||
| 46 | // not a link, just plain text |
||
| 47 | } else { |
||
| 48 | $page = new XMLElement('span', General::sanitize(PageManager::fetchTitleFromHandle($page))); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | if (!$preserve_last) { |
||
| 53 | array_pop($pages); |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->insertBreadcrumbs(array_merge( |
||
| 57 | array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/')), |
||
| 58 | $pages |
||
| 59 | )); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function __viewIndex() |
||
| 63 | { |
||
| 64 | $this->setPageType('table'); |
||
| 65 | $this->setTitle(__('%1$s – %2$s', array(__('Pages'), __('Symphony')))); |
||
| 66 | |||
| 67 | $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'; |
||
| 68 | |||
| 69 | if ($nesting && isset($_GET['parent']) && is_numeric($_GET['parent'])) { |
||
| 70 | $parent = PageManager::fetchPageByID((int)$_GET['parent'], array('title', 'id')); |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->appendSubheading( |
||
| 74 | isset($parent) |
||
| 75 | ? General::sanitize($parent['title']) |
||
| 76 | : __('Pages'), |
||
| 77 | Widget::Anchor( |
||
| 78 | __('Create New'), |
||
| 79 | Administration::instance()->getCurrentPageURL() . 'new/' . ($nesting && isset($parent) ? "?parent={$parent['id']}" : null), |
||
| 80 | __('Create a new page'), |
||
| 81 | 'create button', |
||
| 82 | null, |
||
| 83 | array('accesskey' => 'c') |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | |||
| 87 | if (isset($parent)) { |
||
| 88 | $this->insertBreadcrumbsUsingPageIdentifier($parent['id'], false); |
||
| 89 | } |
||
| 90 | |||
| 91 | $aTableHead = array( |
||
| 92 | array(__('Name'), 'col'), |
||
| 93 | array(__('Template'), 'col'), |
||
| 94 | array('<abbr title="' . __('Universal Resource Locator') . '">' . __('URL') . '</abbr>', 'col'), |
||
| 95 | array(__('Parameters'), 'col'), |
||
| 96 | array(__('Type'), 'col') |
||
| 97 | ); |
||
| 98 | $aTableBody = array(); |
||
| 99 | |||
| 100 | if ($nesting) { |
||
| 101 | $aTableHead[] = array(__('Children'), 'col'); |
||
| 102 | $where = array( |
||
| 103 | 'parent ' . (isset($parent) ? " = {$parent['id']} " : ' IS NULL ') |
||
| 104 | ); |
||
| 105 | } else { |
||
| 106 | $where = array(); |
||
| 107 | } |
||
| 108 | |||
| 109 | $pages = PageManager::fetch(true, array('*'), $where); |
||
| 110 | |||
| 111 | if (!is_array($pages) || empty($pages)) { |
||
| 112 | $aTableBody = array(Widget::TableRow(array( |
||
| 113 | Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead)) |
||
| 114 | ), 'odd')); |
||
| 115 | } else { |
||
| 116 | foreach ($pages as $page) { |
||
| 117 | $class = array(); |
||
| 118 | |||
| 119 | $page_title = ($nesting ? $page['title'] : PageManager::resolvePageTitle($page['id'])); |
||
| 120 | $page_url = URL . '/' . PageManager::resolvePagePath($page['id']) . '/'; |
||
| 121 | $page_edit_url = Administration::instance()->getCurrentPageURL() . 'edit/' . $page['id'] . '/'; |
||
| 122 | $page_template = PageManager::createFilePath($page['path'], $page['handle']); |
||
| 123 | |||
| 124 | $col_title = Widget::TableData( |
||
| 125 | Widget::Anchor(General::sanitize($page_title), $page_edit_url, $page['handle']) |
||
| 126 | ); |
||
| 127 | $col_title->appendChild( |
||
| 128 | Widget::Label( |
||
| 129 | __('Select Page %s', [General::sanitize($page_title)]), |
||
| 130 | null, |
||
| 131 | 'accessible', |
||
| 132 | null, |
||
| 133 | ['for' => 'page-' . $page['id']] |
||
| 134 | ) |
||
| 135 | ); |
||
| 136 | $col_title->appendChild(Widget::Input('items['.$page['id'].']', 'on', 'checkbox', array( |
||
| 137 | 'id' => 'page-' . $page['id'] |
||
| 138 | ))); |
||
| 139 | |||
| 140 | $col_template = Widget::TableData($page_template . '.xsl'); |
||
| 141 | |||
| 142 | $col_url = Widget::TableData(Widget::Anchor($page_url, $page_url)); |
||
| 143 | |||
| 144 | if ($page['params']) { |
||
| 145 | $col_params = Widget::TableData(trim(General::sanitize($page['params']), '/')); |
||
| 146 | } else { |
||
| 147 | $col_params = Widget::TableData(__('None'), 'inactive'); |
||
| 148 | } |
||
| 149 | |||
| 150 | if (!empty($page['type'])) { |
||
| 151 | $col_types = Widget::TableData(implode(', ', array_map(['General', 'sanitize'], $page['type']))); |
||
| 152 | } else { |
||
| 153 | $col_types = Widget::TableData(__('None'), 'inactive'); |
||
| 154 | } |
||
| 155 | |||
| 156 | if (in_array($page['id'], $this->_hilights)) { |
||
| 157 | $class[] = 'failed'; |
||
| 158 | } |
||
| 159 | |||
| 160 | $columns = array($col_title, $col_template, $col_url, $col_params, $col_types); |
||
| 161 | |||
| 162 | if ($nesting) { |
||
| 163 | if (PageManager::hasChildPages($page['id'])) { |
||
| 164 | $col_children = Widget::TableData( |
||
| 165 | Widget::Anchor(PageManager::getChildPagesCount($page['id']) . ' →', |
||
| 166 | SYMPHONY_URL . '/blueprints/pages/?parent=' . $page['id']) |
||
| 167 | ); |
||
| 168 | } else { |
||
| 169 | $col_children = Widget::TableData(__('None'), 'inactive'); |
||
| 170 | } |
||
| 171 | |||
| 172 | $columns[] = $col_children; |
||
| 173 | } |
||
| 174 | |||
| 175 | $aTableBody[] = Widget::TableRow( |
||
| 176 | $columns, |
||
| 177 | implode(' ', $class) |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | $table = Widget::Table( |
||
| 183 | Widget::TableHead($aTableHead), null, |
||
| 184 | Widget::TableBody($aTableBody), 'orderable selectable', |
||
| 185 | null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
||
| 186 | ); |
||
| 187 | |||
| 188 | $this->Form->appendChild($table); |
||
| 189 | |||
| 190 | $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
||
| 191 | 'id' => 'version' |
||
| 192 | )); |
||
| 193 | $this->Form->appendChild($version); |
||
| 194 | |||
| 195 | $tableActions = new XMLElement('div'); |
||
| 196 | $tableActions->setAttribute('class', 'actions'); |
||
| 197 | |||
| 198 | $options = array( |
||
| 199 | array(null, false, __('With Selected...')), |
||
| 200 | array('delete', false, __('Delete'), 'confirm', null, array( |
||
| 201 | 'data-message' => __('Are you sure you want to delete the selected pages?') |
||
| 202 | )) |
||
| 203 | ); |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Allows an extension to modify the existing options for this page's |
||
| 207 | * With Selected menu. If the `$options` parameter is an empty array, |
||
| 208 | * the 'With Selected' menu will not be rendered. |
||
| 209 | * |
||
| 210 | * @delegate AddCustomActions |
||
| 211 | * @since Symphony 2.3.2 |
||
| 212 | * @param string $context |
||
| 213 | * '/blueprints/pages/' |
||
| 214 | * @param array $options |
||
| 215 | * An array of arrays, where each child array represents an option |
||
| 216 | * in the With Selected menu. Options should follow the same format |
||
| 217 | * expected by `Widget::__SelectBuildOption`. Passed by reference. |
||
| 218 | */ |
||
| 219 | Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/blueprints/pages/', array( |
||
| 220 | 'options' => &$options |
||
| 221 | )); |
||
| 222 | |||
| 223 | if (!empty($options)) { |
||
| 224 | $tableActions->appendChild(Widget::Apply($options)); |
||
| 225 | $this->Form->appendChild($tableActions); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | public function __viewNew() |
||
| 232 | } |
||
| 233 | |||
| 234 | public function __viewEdit() |
||
| 235 | { |
||
| 236 | $this->setPageType('form'); |
||
| 237 | $fields = array("title"=>null, "handle"=>null, "parent"=>null, "params"=>null, "type"=>null, "data_sources"=>null); |
||
| 238 | $existing = $fields; |
||
| 239 | $canonical_link = '/blueprints/pages/'; |
||
| 240 | $nesting = (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'); |
||
| 241 | |||
| 242 | // Verify page exists: |
||
| 243 | if ($this->_context[0] === 'edit') { |
||
| 244 | if (!$page_id = (int)$this->_context[1]) { |
||
| 245 | redirect(SYMPHONY_URL . '/blueprints/pages/'); |
||
| 246 | } |
||
| 247 | |||
| 248 | $existing = PageManager::fetchPageByID($page_id); |
||
| 249 | $canonical_link .= 'edit/' . $page_id . '/'; |
||
| 250 | |||
| 251 | if (!$existing) { |
||
| 252 | Administration::instance()->errorPageNotFound(); |
||
| 253 | } else { |
||
| 254 | $existing['type'] = PageManager::fetchPageTypes($page_id); |
||
| 255 | } |
||
| 256 | } else { |
||
| 257 | $canonical_link .= 'new/'; |
||
| 258 | } |
||
| 259 | |||
| 260 | // Status message: |
||
| 261 | if (isset($this->_context[2])) { |
||
| 262 | $flag = $this->_context[2]; |
||
| 263 | $parent_link_suffix = $message = ''; |
||
| 264 | $time = Widget::Time(); |
||
| 265 | |||
| 266 | if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
||
| 267 | $parent_link_suffix = "?parent=" . $_REQUEST['parent']; |
||
| 268 | } elseif ($nesting && isset($existing) && !is_null($existing['parent'])) { |
||
| 269 | $parent_link_suffix = '?parent=' . $existing['parent']; |
||
| 270 | } |
||
| 271 | |||
| 272 | switch ($flag) { |
||
| 273 | case 'saved': |
||
| 274 | $message = __('Page updated at %s.', array($time->generate())); |
||
| 275 | break; |
||
| 276 | case 'created': |
||
| 277 | $message = __('Page created at %s.', array($time->generate())); |
||
| 278 | } |
||
| 279 | |||
| 280 | $this->pageAlert( |
||
| 281 | $message |
||
| 282 | . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/' . $parent_link_suffix . '" accesskey="c">' |
||
| 283 | . __('Create another?') |
||
| 284 | . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' |
||
| 285 | . __('View all Pages') |
||
| 286 | . '</a>', |
||
| 287 | Alert::SUCCESS |
||
| 288 | ); |
||
| 289 | } |
||
| 290 | |||
| 291 | // Find values: |
||
| 292 | if (isset($_POST['fields'])) { |
||
| 293 | $fields = $_POST['fields']; |
||
| 294 | } elseif ($this->_context[0] == 'edit') { |
||
| 295 | $fields = $existing; |
||
| 296 | |||
| 297 | if (!is_null($fields['type'])) { |
||
| 298 | $fields['type'] = implode(', ', $fields['type']); |
||
| 299 | } |
||
| 300 | |||
| 301 | $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); |
||
| 302 | $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); |
||
| 303 | } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
||
| 304 | $fields['parent'] = $_REQUEST['parent']; |
||
| 305 | $canonical_link .= '?parent=' . urlencode($_REQUEST['parent']); |
||
| 306 | } |
||
| 307 | |||
| 308 | $title = $fields['title']; |
||
| 309 | |||
| 310 | if (trim($title) == '') { |
||
| 311 | $title = $existing['title']; |
||
| 312 | } |
||
| 313 | |||
| 314 | $this->setTitle( |
||
| 315 | __( |
||
| 316 | $title |
||
| 317 | ? '%1$s – %2$s – %3$s' |
||
| 318 | : '%2$s – %3$s', |
||
| 319 | array(General::sanitize($title), __('Pages'), __('Symphony')) |
||
| 320 | ) |
||
| 321 | ); |
||
| 322 | $this->addElementToHead(new XMLElement('link', null, array( |
||
| 323 | 'rel' => 'canonical', |
||
| 324 | 'href' => SYMPHONY_URL . $canonical_link, |
||
| 325 | ))); |
||
| 326 | |||
| 327 | $page_id = isset($page_id) ? $page_id : null; |
||
| 328 | |||
| 329 | if (!empty($title)) { |
||
| 330 | $page_url = URL . '/' . PageManager::resolvePagePath($page_id) . '/'; |
||
| 331 | |||
| 332 | $this->appendSubheading( |
||
| 333 | General::sanitize($title), |
||
| 334 | Widget::Anchor( |
||
| 335 | __('View Page'), |
||
| 336 | $page_url, |
||
| 337 | __('View Page on Frontend'), |
||
| 338 | 'button', |
||
| 339 | null, |
||
| 340 | array('target' => '_blank', 'accesskey' => 'v') |
||
| 341 | ) |
||
| 342 | ); |
||
| 343 | } else { |
||
| 344 | $this->appendSubheading(!empty($title) ? General::sanitize($title) : __('Untitled')); |
||
| 345 | } |
||
| 346 | |||
| 347 | if (isset($page_id)) { |
||
| 348 | $this->insertBreadcrumbsUsingPageIdentifier($page_id, false); |
||
| 349 | } else { |
||
| 350 | $_GET['parent'] = isset($_GET['parent']) ? $_GET['parent'] : null; |
||
| 351 | $this->insertBreadcrumbsUsingPageIdentifier((int)$_GET['parent'], true); |
||
| 352 | } |
||
| 353 | |||
| 354 | // Title -------------------------------------------------------------- |
||
| 355 | |||
| 356 | $fieldset = new XMLElement('fieldset'); |
||
| 357 | $fieldset->setAttribute('class', 'settings'); |
||
| 358 | $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); |
||
| 359 | |||
| 360 | $label = Widget::Label(__('Name')); |
||
| 361 | $label->appendChild(Widget::Input( |
||
| 362 | 'fields[title]', General::sanitize($fields['title']) |
||
| 363 | )); |
||
| 364 | |||
| 365 | if (isset($this->_errors['title'])) { |
||
| 366 | $label = Widget::Error($label, $this->_errors['title']); |
||
| 367 | } |
||
| 368 | |||
| 369 | $fieldset->appendChild($label); |
||
| 370 | |||
| 371 | // Handle ------------------------------------------------------------- |
||
| 372 | |||
| 373 | $group = new XMLElement('div'); |
||
| 374 | $group->setAttribute('class', 'two columns'); |
||
| 375 | $column = new XMLElement('div'); |
||
| 376 | $column->setAttribute('class', 'column'); |
||
| 377 | |||
| 378 | $label = Widget::Label(__('Handle')); |
||
| 379 | $label->appendChild(Widget::Input( |
||
| 380 | 'fields[handle]', $fields['handle'] |
||
| 381 | )); |
||
| 382 | |||
| 383 | if (isset($this->_errors['handle'])) { |
||
| 384 | $label = Widget::Error($label, $this->_errors['handle']); |
||
| 385 | } |
||
| 386 | |||
| 387 | $column->appendChild($label); |
||
| 388 | |||
| 389 | // Parent --------------------------------------------------------- |
||
| 390 | |||
| 391 | $label = Widget::Label(__('Parent Page')); |
||
| 392 | |||
| 393 | $where = array( |
||
| 394 | sprintf('id != %d', $page_id) |
||
| 395 | ); |
||
| 396 | $pages = PageManager::fetch(false, array('id'), $where, 'title ASC'); |
||
| 397 | |||
| 398 | $options = array( |
||
| 399 | array('', false, '/') |
||
| 400 | ); |
||
| 401 | |||
| 402 | if (!empty($pages)) { |
||
| 403 | foreach ($pages as $page) { |
||
| 404 | $options[] = array( |
||
| 405 | $page['id'], $fields['parent'] == $page['id'], |
||
| 406 | '/' . PageManager::resolvePagePath($page['id']) |
||
| 407 | ); |
||
| 408 | } |
||
| 409 | |||
| 410 | usort($options, array($this, '__compare_pages')); |
||
| 411 | } |
||
| 412 | |||
| 413 | $label->appendChild(Widget::Select( |
||
| 414 | 'fields[parent]', $options |
||
| 415 | )); |
||
| 416 | $column->appendChild($label); |
||
| 417 | $group->appendChild($column); |
||
| 418 | |||
| 419 | // Parameters --------------------------------------------------------- |
||
| 420 | |||
| 421 | $column = new XMLElement('div'); |
||
| 422 | $column->setAttribute('class', 'column'); |
||
| 423 | |||
| 424 | $label = Widget::Label(__('Parameters')); |
||
| 425 | $label->appendChild(Widget::Input( |
||
| 426 | 'fields[params]', $fields['params'], 'text', array('placeholder' => 'param1/param2') |
||
| 427 | )); |
||
| 428 | $column->appendChild($label); |
||
| 429 | |||
| 430 | // Type ----------------------------------------------------------- |
||
| 431 | |||
| 432 | $label = Widget::Label(__('Type')); |
||
| 433 | $label->appendChild(Widget::Input('fields[type]', $fields['type'])); |
||
| 434 | |||
| 435 | if (isset($this->_errors['type'])) { |
||
| 436 | $label = Widget::Error($label, $this->_errors['type']); |
||
| 437 | } |
||
| 438 | |||
| 439 | $column->appendChild($label); |
||
| 440 | |||
| 441 | $tags = new XMLElement('ul'); |
||
| 442 | $tags->setAttribute('class', 'tags'); |
||
| 443 | $tags->setAttribute('data-interactive', 'data-interactive'); |
||
| 444 | |||
| 445 | $types = PageManager::fetchAvailablePageTypes(); |
||
| 446 | |||
| 447 | foreach ($types as $type) { |
||
| 448 | $tags->appendChild(new XMLElement('li', General::sanitize($type))); |
||
| 449 | } |
||
| 450 | |||
| 451 | $column->appendChild($tags); |
||
| 452 | $group->appendChild($column); |
||
| 453 | $fieldset->appendChild($group); |
||
| 454 | $this->Form->appendChild($fieldset); |
||
| 455 | |||
| 456 | // Events ------------------------------------------------------------- |
||
| 457 | |||
| 458 | $fieldset = new XMLElement('fieldset'); |
||
| 459 | $fieldset->setAttribute('class', 'settings'); |
||
| 460 | $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); |
||
| 461 | |||
| 462 | $group = new XMLElement('div'); |
||
| 463 | $group->setAttribute('class', 'two columns'); |
||
| 464 | |||
| 465 | $label = Widget::Label(__('Events')); |
||
| 466 | $label->setAttribute('class', 'column'); |
||
| 467 | |||
| 468 | $events = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_EVENT, array(), array(), 'name ASC'); |
||
| 469 | $options = array(); |
||
| 470 | |||
| 471 | if (is_array($events) && !empty($events)) { |
||
| 472 | if (!isset($fields['events'])) { |
||
| 473 | $fields['events'] = array(); |
||
| 474 | } |
||
| 475 | |||
| 476 | foreach ($events as $name => $about) { |
||
| 477 | $options[] = array( |
||
| 478 | $name, in_array($name, $fields['events']), $about['name'] |
||
| 479 | ); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); |
||
| 484 | $group->appendChild($label); |
||
| 485 | |||
| 486 | // Data Sources ------------------------------------------------------- |
||
| 487 | |||
| 488 | $label = Widget::Label(__('Data Sources')); |
||
| 489 | $label->setAttribute('class', 'column'); |
||
| 490 | |||
| 491 | $datasources = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_DS, array(), array(), 'name ASC'); |
||
| 492 | $options = array(); |
||
| 493 | |||
| 494 | if (is_array($datasources) && !empty($datasources)) { |
||
| 495 | if (!isset($fields['data_sources'])) { |
||
| 496 | $fields['data_sources'] = array(); |
||
| 497 | } |
||
| 498 | |||
| 499 | foreach ($datasources as $name => $about) { |
||
| 500 | $options[] = array( |
||
| 501 | $name, in_array($name, $fields['data_sources']), $about['name'] |
||
| 502 | ); |
||
| 503 | } |
||
| 504 | } |
||
| 505 | |||
| 506 | $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); |
||
| 507 | $group->appendChild($label); |
||
| 508 | $fieldset->appendChild($group); |
||
| 509 | $this->Form->appendChild($fieldset); |
||
| 510 | |||
| 511 | // Controls ----------------------------------------------------------- |
||
| 512 | |||
| 513 | /** |
||
| 514 | * After all Page related Fields have been added to the DOM, just before the |
||
| 515 | * actions. |
||
| 516 | * |
||
| 517 | * @delegate AppendPageContent |
||
| 518 | * @param string $context |
||
| 519 | * '/blueprints/pages/' |
||
| 520 | * @param XMLElement $form |
||
| 521 | * @param array $fields |
||
| 522 | * @param array $errors |
||
| 523 | */ |
||
| 524 | Symphony::ExtensionManager()->notifyMembers( |
||
| 525 | 'AppendPageContent', |
||
| 526 | '/blueprints/pages/', |
||
| 527 | array( |
||
| 528 | 'form' => &$this->Form, |
||
| 529 | 'fields' => &$fields, |
||
| 530 | 'errors' => $this->_errors |
||
| 531 | ) |
||
| 532 | ); |
||
| 533 | |||
| 534 | $div = new XMLElement('div'); |
||
| 535 | $div->setAttribute('class', 'actions'); |
||
| 536 | $div->appendChild(Widget::Input( |
||
| 537 | 'action[save]', |
||
| 538 | ($this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page')), |
||
| 539 | 'submit', |
||
| 540 | array('accesskey' => 's') |
||
| 541 | )); |
||
| 542 | |||
| 543 | if ($this->_context[0] == 'edit') { |
||
| 544 | $button = new XMLElement('button', __('Delete')); |
||
| 545 | $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); |
||
| 546 | $div->appendChild($button); |
||
| 547 | } |
||
| 548 | |||
| 549 | $this->Form->appendChild($div); |
||
| 550 | |||
| 551 | if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
||
| 552 | $this->Form->appendChild(new XMLElement('input', null, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); |
||
| 553 | } |
||
| 554 | } |
||
| 555 | |||
| 556 | public function __compare_pages($a, $b) |
||
| 557 | { |
||
| 558 | return strnatcasecmp($a[2], $b[2]); |
||
| 559 | } |
||
| 560 | |||
| 561 | public function __actionIndex() |
||
| 562 | { |
||
| 563 | $checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null; |
||
| 564 | |||
| 565 | if (is_array($checked) && !empty($checked)) { |
||
| 566 | /** |
||
| 567 | * Extensions can listen for any custom actions that were added |
||
| 568 | * through `AddCustomPreferenceFieldsets` or `AddCustomActions` |
||
| 569 | * delegates. |
||
| 570 | * |
||
| 571 | * @delegate CustomActions |
||
| 572 | * @since Symphony 2.3.2 |
||
| 573 | * @param string $context |
||
| 574 | * '/blueprints/pages/' |
||
| 575 | * @param array $checked |
||
| 576 | * An array of the selected rows. The value is usually the ID of the |
||
| 577 | * the associated object. |
||
| 578 | */ |
||
| 579 | Symphony::ExtensionManager()->notifyMembers('CustomActions', '/blueprints/pages/', array( |
||
| 580 | 'checked' => $checked |
||
| 581 | )); |
||
| 582 | |||
| 583 | switch ($_POST['with-selected']) { |
||
| 584 | case 'delete': |
||
| 585 | $this->__actionDelete($checked, SYMPHONY_URL . '/blueprints/pages/'); |
||
| 586 | break; |
||
| 587 | } |
||
| 588 | } |
||
| 589 | } |
||
| 590 | |||
| 591 | public function __actionTemplate() |
||
| 592 | { |
||
| 593 | $filename = $this->_context[1] . '.xsl'; |
||
| 594 | $file_abs = PAGES . '/' . $filename; |
||
| 595 | $fields = $_POST['fields']; |
||
| 596 | $this->_errors = array(); |
||
| 597 | |||
| 598 | if (!isset($fields['body']) || trim($fields['body']) == '') { |
||
| 599 | $this->_errors['body'] = __('This is a required field.'); |
||
| 600 | } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { |
||
| 601 | $this->_errors['body'] = __('This document is not well formed.') . ' ' . __('The following error was returned:') . ' <code>' . $errors[0]['message'] . '</code>'; |
||
| 602 | } |
||
| 603 | |||
| 604 | if (empty($this->_errors)) { |
||
| 605 | /** |
||
| 606 | * Just before a Page Template is about to written to disk |
||
| 607 | * |
||
| 608 | * @delegate PageTemplatePreEdit |
||
| 609 | * @since Symphony 2.2.2 |
||
| 610 | * @param string $context |
||
| 611 | * '/blueprints/pages/template/' |
||
| 612 | * @param string $file |
||
| 613 | * The path to the Page Template file |
||
| 614 | * @param string $contents |
||
| 615 | * The contents of the `$fields['body']`, passed by reference |
||
| 616 | */ |
||
| 617 | Symphony::ExtensionManager()->notifyMembers('PageTemplatePreEdit', '/blueprints/pages/template/', array('file' => $file_abs, 'contents' => &$fields['body'])); |
||
| 618 | |||
| 619 | if (!PageManager::writePageFiles($file_abs, $fields['body'])) { |
||
| 620 | $this->pageAlert( |
||
| 621 | __('Page Template could not be written to disk.') |
||
| 622 | . ' ' . __('Please check permissions on %s.', array('<code>/workspace/pages</code>')), |
||
| 623 | Alert::ERROR |
||
| 624 | ); |
||
| 625 | } else { |
||
| 626 | /** |
||
| 627 | * Just after a Page Template has been edited and written to disk |
||
| 628 | * |
||
| 629 | * @delegate PageTemplatePostEdit |
||
| 630 | * @since Symphony 2.2.2 |
||
| 631 | * @param string $context |
||
| 632 | * '/blueprints/pages/template/' |
||
| 633 | * @param string $file |
||
| 634 | * The path to the Page Template file |
||
| 635 | */ |
||
| 636 | Symphony::ExtensionManager()->notifyMembers('PageTemplatePostEdit', '/blueprints/pages/template/', array('file' => $file_abs)); |
||
| 637 | |||
| 638 | redirect(SYMPHONY_URL . '/blueprints/pages/template/' . $this->_context[1] . '/saved/'); |
||
| 639 | } |
||
| 640 | } |
||
| 641 | } |
||
| 642 | |||
| 643 | public function __actionNew() |
||
| 646 | } |
||
| 647 | |||
| 648 | public function __actionEdit() |
||
| 649 | { |
||
| 912 | ); |
||
| 913 | } |
||
| 914 | } |
||
| 915 | } |
||
| 916 | |||
| 917 | public function __actionDelete($pages, $redirect) |
||
| 996 | } |
||
| 997 | } |
||
| 998 | } |
||
| 999 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.