| Conditions | 55 |
| Paths | > 20000 |
| Total Lines | 323 |
| Code Lines | 169 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 193 | public function __form() |
||
| 194 | { |
||
| 195 | // Handle unknown context |
||
| 196 | if (!in_array($this->_context['action'], array('new', 'edit'))) { |
||
| 197 | Administration::instance()->errorPageNotFound(); |
||
| 198 | } |
||
| 199 | |||
| 200 | if ($this->_context['action'] === 'new' && !Symphony::Author()->isDeveloper() && !Symphony::Author()->isManager()) { |
||
| 201 | Administration::instance()->throwCustomError( |
||
| 202 | __('You are not authorised to access this page.'), |
||
| 203 | __('Access Denied'), |
||
| 204 | Page::HTTP_STATUS_UNAUTHORIZED |
||
| 205 | ); |
||
| 206 | } |
||
| 207 | |||
| 208 | if (isset($this->_context['flag'])) { |
||
| 209 | $time = Widget::Time(); |
||
| 210 | |||
| 211 | switch ($this->_context['flag']) { |
||
| 212 | case 'saved': |
||
| 213 | $message = __('Author updated at %s.', array($time->generate())); |
||
| 214 | break; |
||
| 215 | case 'created': |
||
| 216 | $message = __('Author created at %s.', array($time->generate())); |
||
| 217 | } |
||
| 218 | |||
| 219 | $this->pageAlert( |
||
| 220 | $message |
||
| 221 | . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' |
||
| 222 | . __('Create another?') |
||
| 223 | . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' |
||
| 224 | . __('View all Authors') |
||
| 225 | . '</a>', |
||
| 226 | Alert::SUCCESS |
||
| 227 | ); |
||
| 228 | } |
||
| 229 | |||
| 230 | $this->setPageType('form'); |
||
| 231 | $isOwner = false; |
||
| 232 | $isEditing = ($this->_context['action'] === 'edit'); |
||
| 233 | |||
| 234 | if (isset($_POST['fields'])) { |
||
| 235 | $author = $this->_Author; |
||
| 236 | } elseif ($isEditing) { |
||
| 237 | if (!$author_id = $this->_context['id']) { |
||
| 238 | redirect(SYMPHONY_URL . '/system/authors/'); |
||
| 239 | } |
||
| 240 | |||
| 241 | if (!$author = AuthorManager::fetchByID($author_id)) { |
||
| 242 | Administration::instance()->throwCustomError( |
||
| 243 | __('The author profile you requested does not exist.'), |
||
| 244 | __('Author not found'), |
||
| 245 | Page::HTTP_STATUS_NOT_FOUND |
||
| 246 | ); |
||
| 247 | } |
||
| 248 | } else { |
||
| 249 | $author = new Author; |
||
| 250 | } |
||
| 251 | |||
| 252 | if ($isEditing && $author->get('id') === Symphony::Author()->get('id')) { |
||
| 253 | $isOwner = true; |
||
| 254 | } |
||
| 255 | |||
| 256 | if ($isEditing && !$isOwner && !Symphony::Author()->isDeveloper() && !Symphony::Author()->isManager()) { |
||
| 257 | Administration::instance()->throwCustomError( |
||
| 258 | __('You are not authorised to edit other authors.'), |
||
| 259 | __('Access Denied'), |
||
| 260 | Page::HTTP_STATUS_FORBIDDEN |
||
| 261 | ); |
||
| 262 | } |
||
| 263 | |||
| 264 | $this->setTitle(__(($this->_context['action'] === 'new' ? '%2$s – %3$s' : '%1$s – %2$s – %3$s'), array($author->getFullName(), __('Authors'), __('Symphony')))); |
||
| 265 | $this->appendSubheading(($this->_context['action'] === 'new' ? __('Untitled') : $author->getFullName())); |
||
| 266 | $this->insertBreadcrumbs(array( |
||
| 267 | Widget::Anchor(__('Authors'), SYMPHONY_URL . '/system/authors/'), |
||
| 268 | )); |
||
| 269 | |||
| 270 | // Essentials |
||
| 271 | $group = new XMLElement('fieldset'); |
||
| 272 | $group->setAttribute('class', 'settings'); |
||
| 273 | $group->appendChild(new XMLElement('legend', __('Essentials'))); |
||
| 274 | |||
| 275 | $div = new XMLElement('div'); |
||
| 276 | $div->setAttribute('class', 'two columns'); |
||
| 277 | |||
| 278 | $label = Widget::Label(__('First Name'), null, 'column'); |
||
| 279 | $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name'))); |
||
| 280 | $div->appendChild((isset($this->_errors['first_name']) ? Widget::Error($label, $this->_errors['first_name']) : $label)); |
||
| 281 | |||
| 282 | |||
| 283 | $label = Widget::Label(__('Last Name'), null, 'column'); |
||
| 284 | $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name'))); |
||
| 285 | $div->appendChild((isset($this->_errors['last_name']) ? Widget::Error($label, $this->_errors['last_name']) : $label)); |
||
| 286 | |||
| 287 | $group->appendChild($div); |
||
| 288 | |||
| 289 | $label = Widget::Label(__('Email Address')); |
||
| 290 | $label->appendChild(Widget::Input('fields[email]', $author->get('email'), 'text', array('autocomplete' => 'off'))); |
||
| 291 | $group->appendChild((isset($this->_errors['email']) ? Widget::Error($label, $this->_errors['email']) : $label)); |
||
| 292 | |||
| 293 | $this->Form->appendChild($group); |
||
| 294 | |||
| 295 | // Login Details |
||
| 296 | $group = new XMLElement('fieldset'); |
||
| 297 | $group->setAttribute('class', 'settings'); |
||
| 298 | $group->appendChild(new XMLElement('legend', __('Login Details'))); |
||
| 299 | |||
| 300 | $div = new XMLElement('div'); |
||
| 301 | |||
| 302 | $label = Widget::Label(__('Username')); |
||
| 303 | $label->appendChild(Widget::Input('fields[username]', $author->get('username'), 'text', array('autocomplete' => 'off'))); |
||
| 304 | $div->appendChild((isset($this->_errors['username']) ? Widget::Error($label, $this->_errors['username']) : $label)); |
||
| 305 | |||
| 306 | // Only developers can change the user type. Primary account should NOT be able to change this |
||
| 307 | if ((Symphony::Author()->isDeveloper() || Symphony::Author()->isManager()) && !$author->isPrimaryAccount()) { |
||
| 308 | |||
| 309 | // Create columns |
||
| 310 | $div->setAttribute('class', 'two columns'); |
||
| 311 | $label->setAttribute('class', 'column'); |
||
| 312 | |||
| 313 | // User type |
||
| 314 | $label = Widget::Label(__('User Type'), null, 'column'); |
||
| 315 | |||
| 316 | $options = array( |
||
| 317 | array('author', false, __('Author')), |
||
| 318 | array('manager', $author->isManager(), __('Manager')) |
||
| 319 | ); |
||
| 320 | |||
| 321 | if (Symphony::Author()->isDeveloper()) { |
||
| 322 | $options[] = array('developer', $author->isDeveloper(), __('Developer')); |
||
| 323 | } |
||
| 324 | |||
| 325 | $label->appendChild(Widget::Select('fields[user_type]', $options)); |
||
| 326 | $div->appendChild($label); |
||
| 327 | } |
||
| 328 | |||
| 329 | $group->appendChild($div); |
||
| 330 | |||
| 331 | // Password |
||
| 332 | $fieldset = new XMLElement('fieldset', null, array('class' => 'two columns', 'id' => 'password')); |
||
| 333 | $legend = new XMLElement('legend', __('Password')); |
||
| 334 | $help = new XMLElement('i', __('Leave password fields blank to keep the current password')); |
||
| 335 | $fieldset->appendChild($legend); |
||
| 336 | $fieldset->appendChild($help); |
||
| 337 | |||
| 338 | /* |
||
| 339 | Password reset rules: |
||
| 340 | - Primary account can edit all accounts. |
||
| 341 | - Developers can edit all developers, managers and authors, and their own. |
||
| 342 | - Managers can edit all Authors, and their own. |
||
| 343 | - Authors can edit their own. |
||
| 344 | */ |
||
| 345 | if ($isEditing && !( |
||
| 346 | // All accounts can edit their own |
||
| 347 | $isOwner |
||
| 348 | // Managers can edit all Authors, and their own. |
||
| 349 | || (Symphony::Author()->isManager() && $author->isAuthor()) |
||
| 350 | // Primary account can edit all accounts. |
||
| 351 | || Symphony::Author()->isPrimaryAccount() |
||
| 352 | // Developers can edit all developers, managers and authors, and their own. |
||
| 353 | || Symphony::Author()->isDeveloper() && $author->isPrimaryAccount() === false |
||
| 354 | )) { |
||
| 355 | $fieldset->setAttribute('class', 'three columns'); |
||
| 356 | |||
| 357 | $label = Widget::Label(null, null, 'column'); |
||
| 358 | $label->appendChild(Widget::Input('fields[old-password]', null, 'password', array('placeholder' => __('Old Password'), 'autocomplete' => 'off'))); |
||
| 359 | $fieldset->appendChild((isset($this->_errors['old-password']) ? Widget::Error($label, $this->_errors['old-password']) : $label)); |
||
| 360 | } |
||
| 361 | |||
| 362 | // New password |
||
| 363 | $placeholder = ($isEditing ? __('New Password') : __('Password')); |
||
| 364 | $label = Widget::Label(null, null, 'column'); |
||
| 365 | $label->appendChild(Widget::Input('fields[password]', null, 'password', array('placeholder' => $placeholder, 'autocomplete' => 'off'))); |
||
| 366 | $fieldset->appendChild((isset($this->_errors['password']) ? Widget::Error($label, $this->_errors['password']) : $label)); |
||
| 367 | |||
| 368 | // Confirm password |
||
| 369 | $label = Widget::Label(null, null, 'column'); |
||
| 370 | $label->appendChild(Widget::Input('fields[password-confirmation]', null, 'password', array('placeholder' => __('Confirm Password'), 'autocomplete' => 'off'))); |
||
| 371 | $fieldset->appendChild((isset($this->_errors['password-confirmation']) ? Widget::Error($label, $this->_errors['password']) : $label)); |
||
| 372 | |||
| 373 | $group->appendChild($fieldset); |
||
| 374 | |||
| 375 | // Auth token |
||
| 376 | if (Symphony::Author()->isDeveloper() || Symphony::Author()->isManager()) { |
||
| 377 | $label = Widget::Label(); |
||
| 378 | $group->appendChild(Widget::Input('fields[auth_token_active]', 'no', 'hidden')); |
||
| 379 | $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); |
||
| 380 | |||
| 381 | if ($author->isTokenActive()) { |
||
| 382 | $input->setAttribute('checked', 'checked'); |
||
| 383 | } |
||
| 384 | |||
| 385 | $temp = SYMPHONY_URL . '/login/' . $author->createAuthToken() . '/'; |
||
| 386 | $label->setValue(__('%s Allow remote login via', array($input->generate())) . ' <a href="' . $temp . '">' . $temp . '</a>'); |
||
| 387 | $group->appendChild($label); |
||
| 388 | } |
||
| 389 | |||
| 390 | $label = Widget::Label(__('Default Area')); |
||
| 391 | |||
| 392 | $sections = SectionManager::fetch(null, 'ASC', 'sortorder'); |
||
| 393 | |||
| 394 | $options = array(); |
||
| 395 | |||
| 396 | // If the Author is the Developer, allow them to set the Default Area to |
||
| 397 | // be the Sections Index. |
||
| 398 | if ($author->isDeveloper()) { |
||
| 399 | $options[] = array('/blueprints/sections/', $author->get('default_area') === '/blueprints/sections/', __('Sections Index')); |
||
| 400 | } |
||
| 401 | |||
| 402 | if (is_array($sections) && !empty($sections)) { |
||
| 403 | foreach ($sections as $s) { |
||
| 404 | $options[] = array($s->get('id'), $author->get('default_area') === $s->get('id'), $s->get('name')); |
||
| 405 | } |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Allows injection or manipulation of the Default Area dropdown for an Author. |
||
| 410 | * Take care with adding in options that are only valid for Developers, as if a |
||
| 411 | * normal Author is set to that option, they will be redirected to their own |
||
| 412 | * Author record. |
||
| 413 | * |
||
| 414 | * |
||
| 415 | * @delegate AddDefaultAuthorAreas |
||
| 416 | * @since Symphony 2.2 |
||
| 417 | * @param string $context |
||
| 418 | * '/system/authors/' |
||
| 419 | * @param array $options |
||
| 420 | * An associative array of options, suitable for use for the Widget::Select |
||
| 421 | * function. By default this will be an array of the Sections in the current |
||
| 422 | * installation. New options should be the path to the page after the `SYMPHONY_URL` |
||
| 423 | * constant. |
||
| 424 | * @param string $default_area |
||
| 425 | * The current `default_area` for this Author. |
||
| 426 | */ |
||
| 427 | Symphony::ExtensionManager()->notifyMembers('AddDefaultAuthorAreas', '/system/authors/', array( |
||
| 428 | 'options' => &$options, |
||
| 429 | 'default_area' => $author->get('default_area') |
||
| 430 | )); |
||
| 431 | |||
| 432 | $label->appendChild(Widget::Select('fields[default_area]', $options)); |
||
| 433 | $group->appendChild($label); |
||
| 434 | |||
| 435 | $this->Form->appendChild($group); |
||
| 436 | |||
| 437 | // Custom Language Selection |
||
| 438 | $languages = Lang::getAvailableLanguages(); |
||
| 439 | if (count($languages) > 1) { |
||
| 440 | // Get language names |
||
| 441 | asort($languages); |
||
| 442 | |||
| 443 | $group = new XMLElement('fieldset'); |
||
| 444 | $group->setAttribute('class', 'settings'); |
||
| 445 | $group->appendChild(new XMLElement('legend', __('Custom Preferences'))); |
||
| 446 | |||
| 447 | $label = Widget::Label(__('Language')); |
||
| 448 | |||
| 449 | $options = array( |
||
| 450 | array(null, is_null($author->get('language')), __('System Default')) |
||
| 451 | ); |
||
| 452 | |||
| 453 | foreach ($languages as $code => $name) { |
||
| 454 | $options[] = array($code, $code === $author->get('language'), $name); |
||
| 455 | } |
||
| 456 | $select = Widget::Select('fields[language]', $options); |
||
| 457 | $label->appendChild($select); |
||
| 458 | $group->appendChild($label); |
||
| 459 | |||
| 460 | $this->Form->appendChild($group); |
||
| 461 | } |
||
| 462 | |||
| 463 | // Administration password double check |
||
| 464 | if ($isEditing && !$isOwner) { |
||
| 465 | $group = new XMLElement('fieldset'); |
||
| 466 | $group->setAttribute('class', 'settings'); |
||
| 467 | $group->setAttribute('id', 'confirmation'); |
||
| 468 | $group->appendChild(new XMLElement('legend', __('Confirmation'))); |
||
| 469 | $group->appendChild(new XMLELement('p', __('Please confirm changes to this author with your password.'), array('class' => 'help'))); |
||
| 470 | |||
| 471 | $label = Widget::Label(__('Password')); |
||
| 472 | $label->appendChild(Widget::Input('fields[confirm-change-password]', null, 'password', array( |
||
| 473 | 'autocomplete' => 'off', |
||
| 474 | 'placeholder' => __('Your Password') |
||
| 475 | ))); |
||
| 476 | $group->appendChild( |
||
| 477 | isset($this->_errors['confirm-change-password']) ? Widget::Error($label, $this->_errors['confirm-change-password']) : $label |
||
| 478 | ); |
||
| 479 | |||
| 480 | $this->Form->appendChild($group); |
||
| 481 | } |
||
| 482 | |||
| 483 | // Actions |
||
| 484 | $div = new XMLElement('div'); |
||
| 485 | $div->setAttribute('class', 'actions'); |
||
| 486 | |||
| 487 | $div->appendChild(Widget::Input('action[save]', ($this->_context['action'] === 'edit' ? __('Save Changes') : __('Create Author')), 'submit', array('accesskey' => 's'))); |
||
| 488 | |||
| 489 | if ($isEditing && !$isOwner && !$author->isPrimaryAccount()) { |
||
| 490 | $button = new XMLElement('button', __('Delete')); |
||
| 491 | $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this author'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this author?'))); |
||
| 492 | $div->appendChild($button); |
||
| 493 | } |
||
| 494 | |||
| 495 | $this->Form->appendChild($div); |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Allows the injection of custom form fields given the current `$this->Form` |
||
| 499 | * object. Please note that this custom data should be saved in own extension |
||
| 500 | * tables and that modifying `tbl_authors` to house your data is highly discouraged. |
||
| 501 | * |
||
| 502 | * @delegate AddElementstoAuthorForm |
||
| 503 | * @since Symphony 2.2 |
||
| 504 | * @param string $context |
||
| 505 | * '/system/authors/' |
||
| 506 | * @param XMLElement $form |
||
| 507 | * The contents of `$this->Form` after all the default form elements have been appended. |
||
| 508 | * @param Author $author |
||
| 509 | * The current Author object that is being edited |
||
| 510 | */ |
||
| 511 | Symphony::ExtensionManager()->notifyMembers('AddElementstoAuthorForm', '/system/authors/', array( |
||
| 512 | 'form' => &$this->Form, |
||
| 513 | 'author' => $author |
||
| 514 | )); |
||
| 515 | } |
||
| 516 | |||
| 750 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.