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